[class.pre] (original) (raw)
11 Classes [class]
11.1 Preamble [class.pre]
A class is a type.
Its name becomes a class-name ([class.name]) within its scope.
An object of a class consists of a (possibly empty) sequence of members and base class objects.
class-key:
class
struct
union
A class-specifier whoseclass-head omits theclass-head-name defines an unnamed class.
[Note 1:
An unnamed class thus can't be final.
— _end note_]
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 2:
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_]
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 1: struct A;struct A final {}; struct X { struct C { constexpr operator int() { return 5; } };struct B final : C{}; }; — _end example_]
[Note 3:
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 4:
Other plausible operators, such as equality comparison, can be defined by the user; see [over.oper].
— _end note_]