Relation between classes and fundamental types

73 views
Skip to first unread message

Andrey Semashev

unread,
Jan 14, 2017, 8:21:33 AM1/14/17
to ISO C++ Standard - Discussion
Hi,

Reading the standard, I'm confused as to how classes and fundamental
types are related. [class]/1 says that class is a type and then goes on
to specify what a class-name is and how classes are defined (i.e. using
class-key class, struct or union).

This definition seems to exclude the fundamental types like int or
enums. If that's the case, the following definitions of
trivially-copyable, trivial, standard-layout classes and POD struct do
not apply to those types. Does that mean that fundamental types and
enums are not considered trivial, standard-layout or POD?

Also, in the POD-struct definition ([class]/10) there is an example that
shows that trivial, standard-layout and POD types can have ints. So it
seems that the intention is to include at least fundamental types into
the notion of a class. It's not clear about enums though.

So the question is, are fundamental types and enums also considered
classes or is there a defect in the example?

Nicol Bolas

unread,
Jan 14, 2017, 9:55:32 AM1/14/17
to ISO C++ Standard - Discussion


On Saturday, January 14, 2017 at 8:21:33 AM UTC-5, Andrey Semashev wrote:
Hi,

Reading the standard, I'm confused as to how classes and fundamental
types are related. [class]/1 says that class is a type and then goes on
to specify what a class-name is and how classes are defined (i.e. using
class-key class, struct or union). 

This definition seems to exclude the fundamental types like int or
enums.

All classes are types. This does not mean all types are classes. Classes are a strict subset of types.

T. C.

unread,
Jan 14, 2017, 9:59:22 AM1/14/17
to ISO C++ Standard - Discussion


On Saturday, January 14, 2017 at 8:21:33 AM UTC-5, Andrey Semashev wrote:

Hi,

Reading the standard, I'm confused as to how classes and fundamental
types are related. [class]/1 says that class is a type and then goes on
to specify what a class-name is and how classes are defined (i.e. using
class-key class, struct or union).

This definition seems to exclude the fundamental types like int or
enums. If that's the case, the following definitions of
trivially-copyable, trivial, standard-layout classes and POD struct do
not apply to those types. Does that mean that fundamental types and
enums are not considered trivial, standard-layout or POD?

Howard Hinnant

unread,
Jan 14, 2017, 11:35:56 AM1/14/17
to std-dis...@isocpp.org
On Jan 14, 2017, at 8:21 AM, Andrey Semashev <andrey....@gmail.com> wrote:
>
> So the question is, are fundamental types and enums also considered classes or is there a defect in the example?

No.

Handy chart for type classification based on section 3.9 Types [basic.types]:

http://howardhinnant.github.io/TypeHiearchy.pdf

Howard

Andrey Semashev

unread,
Jan 14, 2017, 2:53:23 PM1/14/17
to std-dis...@isocpp.org
Thanks, I missed that paragraph.

Andrey Semashev

unread,
Jan 14, 2017, 2:56:30 PM1/14/17
to std-dis...@isocpp.org
Thanks, although I find that graph quite confusing. In particular, it's
not clear why there is an object node if the graph describes type
categories.

Howard Hinnant

unread,
Jan 14, 2017, 3:06:32 PM1/14/17
to std-dis...@isocpp.org
This comes from [basic.types]/p8:

> An object type is a (possibly cv-qualified) type that is not a function type, not a reference type, and not cv void.

Howard

barry....@gmail.com

unread,
Jan 19, 2017, 8:13:41 AM1/19/17
to ISO C++ Standard - Discussion

Handy chart for type classification based on section 3.9 Types [basic.types]:

http://howardhinnant.github.io/TypeHiearchy.pdf

Howard


That graph is awesome. Can we just stick it in the standard? Standard needs more graphs. 
Reply all
Reply to author
Forward
0 new messages