Declaring class types (C++ only)

A class declaration creates a unique type class name.

A class specifier is a type specifier used to declare a class. Once a class specifier has been seen and its members declared, a class is considered to be defined even if the member functions of that class are not yet defined.

Read syntax diagramSkip visual syntax diagram
Class specifier syntax

>>-+-class--+--class_name--+----------------+------------------->
   +-struct-+              '-:--base_clause-'   
   '-union--'                                   

>--{--+-------------+--}---------------------------------------><
      '-member_list-'      

The class_name is a unique identifier that becomes a reserved word within its scope. Once a class name is declared, it hides other declarations of the same name within the enclosing scope.

The member_list specifies the class members, both data and functions, of the class class_name. If the member_list of a class is empty, objects of that class have a nonzero size. You can use a class_name within the member_list of the class specifier itself as long as the size of the class is not required.

The base_clause specifies the base class or classes from which the class class_name inherits members. If the base_clause is not empty, the class class_name is called a derived class.

A structure is a class declared with the class_key struct. The members and base classes of a structure are public by default. A union is a class declared with the class_key union. The members of a union are public by default; a union holds only one data member at a time.

An aggregate class is a class that has no user-defined constructors, no private or protected non-static data members, no base classes, and no virtual functions.