[class.pre] (original) (raw)

11 Classes [class]

11.1 Preamble [class.pre]

A class-name is inserted into the scope in which it is declared immediately after the class-name is seen.

Theclass-name is also inserted into the scope of the class itself; this is known as the injected-class-name.

For purposes of access checking, the injected-class-name is treated as if it were a public member name.

A class-specifier is commonly referred to as a class definition.

A class is considered defined after the closing brace of itsclass-specifier has been seen even though its member functions are in general not yet defined.

If a class-head-name contains a nested-name-specifier, the class-specifier shall refer to a class that was previously declared directly in the class or namespace to which thenested-name-specifier refers, or in an element of the inline namespace set ([namespace.def]) of that namespace (i.e., not merely inherited or introduced by a using-declaration), and theclass-specifier shall appear in a namespace enclosing the previous declaration.

[ Note

:

The class-key determines whether the class is a union ([class.union]) and whether access is public or private by default ([class.access]).

A union holds the value of at most one data member at a time.

end note

]

If a class is marked with the class-virt-specifier final and it appears as a class-or-decltype in a base-clause, the program is ill-formed.

Whenever aclass-key is followed by a class-head-name, theidentifier final, and a colon or left brace, final is interpreted as a class-virt-specifier.

[ Example

:

struct A; struct A final {};

struct X { struct C { constexpr operator int() { return 5; } }; struct B final : C{};

};

end example

]

[ Note

:

Complete objects of class type have nonzero size.

Base class subobjects and members declared with the no_­unique_­address attribute ([dcl.attr.nouniqueaddr]) are not so constrained.

end note

]

[ Note

:

Other plausible operators, such as equality comparison, can be defined by the user; see [over.oper].

end note

]