cpp/language/class

Classes are user-defined types, defined by class-specifier, which appears in of the  syntax.

Syntax
The class specifier has the following syntax:

@1@ named class definition @2@ unnamed class definition

Forward declaration
A declaration of the following form

Declares a class type which will be defined later in this scope. Until the definition appears, this class name has. This allows classes that refer to each other:

and if a particular source file only uses pointers and references to the class, this makes it possible to reduce #include dependencies:

If forward declaration appears in local scope, it hides previously declared class, variable, function, and all other declarations of the same name that may appear in enclosing scopes:

Note that a new class name may also be introduced by an which appears as part of another declaration, but only if  can't find a previously declared class with the same name.

Member specification
The member specification, or the body of a class definition, is a brace-enclosed sequence of any number of the following: @1@ Member declarations of the form

This declaration may declare and non-static  and, member s, member , and. It may also be a.

@2@ Function definitions, which both declare and define or. A semicolon after a member function definition is optional. All functions that are defined inside a class body are automatically.

@3@, , and

@4@ :

@5@ declarations:

@6@ :

Local classes
A class declaration can appear inside the body of a function, in which case it defines a local class. The name of such a class only exists within the function scope, and is not accessible outside.


 * A local class cannot have static data members
 * Member functions of a local class have no linkage
 * Member functions of a local class have to be defined entirely inside the class body
 * Local classes cannot have member templates
 * Local classes cannot have
 * Local classes cannot define inside the class definition
 * A local class inside a function (including member function) can access the same names that the enclosing function can access.