Nested classes

You can define a class within a class. If the nested class is declared as public, then you can create objects in the container class and return them to external code. Typically, however, you will want to declare a class that is used by the class and should be private. The following declares a public nested class:

    class outer 
{
public:
class inner
{
public:
void f();
};

inner g() { return inner(); }
};

void outer::inner::f()
{
// do something
}

Notice how the name of the nested class is prefixed with the name of the containing class.