Class member lists (C++ only)

An optional member list declares subobjects called class members. Class members can be data, functions, nested types, and enumerators.

Read syntax diagramSkip visual syntax diagramClass member list syntax
   V                                                       |
     |                     +-=--0-------------------+    |
     |                     '-=--constant_expression-'    |

The member list follows the class name and is placed between braces. The following applies to member lists, and members of member lists:

A constant initializer (= constant_expression) may only appear in a class member of integral or enumeration type that has been declared static.

A pure specifier (= 0) indicates that a function has no definition. It is only used with member functions declared as virtual and replaces the function definition of a member function in the member list.

An access specifier is one of public, private, or protected.

A member declaration declares a class member for the class containing the declaration.

The order of allocation of nonstatic class members separated by an access_specifier is implementation-dependent. The compiler allocates class members in the order in which they are declared.

Suppose A is a name of a class. The following class members of A must have a name different from A:

Related information