cpp/language/nested types

A declaration of a or  may appear within another class. Such declaration declares a nested class.

Explanation
The name of the nested class exists in the scope of the enclosing class, and name lookup from a member function of a nested class visits the scope of the enclosing class after examining the scope of the nested class. Like any member of its enclosing class, the nested class has access to all names (private, protected, etc) to which the enclosing class has access, but it is otherwise independent and has no special access to the of the enclosing class. Declarations in a nested class can use any members of the enclosing class, following the for the non-static members.

functions defined within a nested class have no special access to the members of the enclosing class even if lookup from the body of a member function that is defined within a nested class can find the private members of the enclosing class.

Out-of-class definitions of the members of a nested class appear in the namespace of the enclosing class:

Nested classes can be forward-declared and later defined, either within the same enclosing class body, or outside of it:

Nested class declarations obey specifiers, a private member class cannot be named outside the scope of the enclosing class, although objects of that class may be manipulated: