https://en.cppreference.com/w/cpp/language/classes
A class is a user-defined type.
A class type is defined by class-specifier, which appears in
of the
syntax. The class specifier has the following syntax:
}}
}}
]] | one of {{ltt | cpp/keyword/class}}, {{ltt | cpp/keyword/struct}}, {{ltt | cpp/keyword/union}}}} {{par | {{spar | attr}} | {{mark since c++11}} optional sequence of any number of {{rlp | attributes}}}} {{par | {{spar | class-head-name}} | the name of the class that's being defined. Optionally prepended by {{spar | nested-name-specifier}} (sequence of names and scope-resolution operators, ending with scope-resolution operator), optionally followed by keyword {{ltt | cpp/keyword/final}}. The name may be omitted, in which case the class is unnamed (note that unnamed class cannot be final) }} {{par | {{spar | base-specifier-list}} | list of one or more parent classes and the model of inheritance used for each (see {{rlp | derived_class | derived class}}) }} {{par | {{spar | member-specification}} | list of access specifiers, member object and member function declarations and definitions (see {{rlp | class | class definition}})}} {{par end}} The class keys {{tt | struct}} and {{tt | class}} are indistinguishable in C++, except that the default {{rlp | access | access mode}} and default {{rlp | derived class | inheritance mode}} are {{tt | public}} if class declaration uses the {{tt | struct}} {{spar | class-key}} and {{tt | private}} if the class declaration uses the {{tt | class}} {{spar | class-key}}. Both {{tt | class}} and {{tt | struct}} can be used in a {{rlp | class | class definition}}. The use of the class key {{tt | union}} results in a {{rlp | union | @a@ {{rlp | data members | non-static data members}}, including {{rlp | bit_field | @b@ {{rlp | Static data members | @a@ {{rlp | member functions | @b@ {{rlp | Static member functions | @a@ {{rlp | nested classes}} and {{rlp | enum | @b@ aliases of existing types, defined with {{rlpt | typedef}} {{rev inl | since=c++11 | or {{rlp | @c@ the name of the class within its own definition acts as a public member type alias of itself for the purpose of {{rlp | Injected_class_name | lookup}} (except when used to name a {{rlp | this is known as ''{{rlp | injected-class-name}}'' @4@ {{rlp | enum | enumerators}} from all unscoped enumerations defined within the class{{rev inl | since=c++20 | , or introduced by {{rlp | using declaration | using-declaration}}s or {{rlp | Using-enum-declaration | using-enum-declaration}}s}} @5@ {{rlp | member_template | member templates}} ({{rev inl | since=c++14 | variable templates, }}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 {{tt | T}} cannot use {{tt | T}} as its name if the member is a static data member, a member function, a member type, a member template{{mark unreviewed dr | CWG | 1909}}, an enumerator of an unscoped enumeration, a member of a member anonymous union. However, a non-static data member may use the name {{tt | T}} as long as there are no user-declared constructors. A class with at least one declared or inherited {{rlp | virtual}} member function is ''polymorphic''. Objects of this type are {{rlp | Polymorphic_objects | polymorphic objects}} and have runtime type information stored as part of the object representation, which may be queried with {{rlpt | dynamic_cast}} and {{rlpt | typeid}}. Virtual member functions participate in dynamic binding. A class with at least one declared or inherited pure virtual member function is an {{rlp | abstract class}}. Objects of this type cannot be created. {{rrev | since=c++11 | A class with a {{rlp | constexpr}} constructor is a {{named req | objects of this type can be manipulated by {{rlp | * {{rlp | default_constructor | Default constructor}} * {{rlp | copy_constructor | Copy constructor}} {{rrev | since=c++11 | noborder=true | * {{rlp | move_constructor | Move constructor}} }} * {{rlp | copy_assignment | Copy assignment operator}} {{rrev | since=c++11 | noborder=true | * {{rlp | move_assignment | Move assignment operator}} }} * {{rlp | destructor | Destructor}} {{langlinks | ja | ru | [[zh}}