A nested class is declared within the scope of another class. The name of a nested class is local to its enclosing class . Unless you use explicit pointers, references, or object names , declarations in a nested class can only use visible constructs, including type names, static members, and enumerators from the enclosing class and global variables.
Member functions of a nested class follow regular access rules and have no special access privileges to members of their enclosing classes. Member functions of the enclosing class have no special access to members of a nested class.
You can define member functions and static data members of a
nested class in the global scope. For example , in the following
code fragment, you can access the static members x and y and
member functions f() and g() of the nested class nested by using
a qualified type name. Qualified type names allow you to define a
typedef to represent a qualified class name. You can then use the
typedef with the :: (scope resolution) operator to refer to a
nested class or class member, as shown in the following example:
class outside { public: class nested { public: static int x; static int y; int f(); int g(); }; }; int outside::nested::x = 5; int outside::nested::f() { return 0; }; typedef outside::nested outnest; // define a typedef int outnest::y = 10; // use typedef with :: int outnest::g() { return 0; }; // . . .