cpp/language/classes

A class is a user-defined type.

A class type is defined by class-specifier, which appears in of the  syntax. See for the syntax of the class specifier.

A class can have the following kinds of members: @1@ data members:
 * @a@, including.
 * @b@

@2@ member functions:
 * @a@
 * @b@

@3@ nested types:
 * @a@ and  defined within the class definition
 * @b@ aliases of existing types, defined with declarations
 * @c@ the name of the class within its own definition acts as a public member type alias of itself for the purpose of (except when used to name a ): this is known as 

@4@ from all unscoped enumerations defined within the class @5@ s (class templates or function templates) may appear in the body of any non-local class/struct/union.

All members are defined at once in the class definition, they cannot be added to an already-defined class (unlike the members of namespaces)

A member of a class cannot use  as its name if the member is However, a non-static data member may use the name  as long as there are no user-declared constructors.
 * a static data member,
 * a member function,
 * a member type,
 * a member template,
 * an enumerator of an enumeration, or
 * a member of a member anonymous union.

A class with at least one declared or inherited member function is polymorphic. Objects of this type are and have runtime type information stored as part of the object representation, which may be queried with  and. Virtual member functions participate in dynamic binding.

A class with at least one declared or inherited pure virtual member function is an. Objects of this type cannot be created.

Properties of classes
{{rrev|since=c++11|

Trivially copyable class
A trivially copyable class is a class that
 * has at least one eligible, , , or ,
 * each eligible copy constructor is
 * each eligible move constructor is
 * each eligible copy assignment operator is
 * each eligible move assignment operator is, and
 * has a non-deleted.

Trivial class
A trivial class is a class that
 * is trivially copyable, and
 * has one or more such that each is.

Standard-layout class
A standard-layout class is a class that
 * has no of type non-standard-layout class (or array of such types) or reference,
 * has no and no ,
 * has the same for all non-static data members,
 * has no non-standard-layout base classes,
 * only one class in the hierarchy has non-static data members, and


 * Informally, none of the base classes has the same type as the first non-static data member. Or, formally: given the class as S, has no element of the set M(S) of types as a base class, where M(X) for a type X is defined as:
 * If X is a non-union class type with no (possibly inherited) non-static data members, the set M(X) is empty.
 * If X is a non-union class type whose first non-static data member has type X0 (where said member may be an anonymous union), the set M(X) consists of X0 and the elements of M(X0).
 * If X is a union type, the set M(X) is the union of all M(Ui) and the set containing all Ui, where each Ui is the type of the ith non-static data member of X.
 * If X is an array type with element type Xe, the set M(X) consists of Xe and the elements of M(Xe).
 * If X is a non-class, non-array type, the set M(X) is empty.

A standard-layout struct is a standard-layout class defined with the class keyword or the class keyword. A standard-layout union is a standard-layout class defined with the class keyword. }}

Implicit-lifetime class
An implicit-lifetime class is a class that
 * is an whose destructor is not, or
 * has at least one trivial eligible constructor and a trivial, non-deleted destructor.

Notes: the implicit-lifetime property is clarified by defect report.

POD class
A POD class is a class that

A POD struct is a non-union POD class. A POD union is a union that is a POD class.