Example of Using a typedef for a Class Name


/************************************************************************
*

In the following example, a typedef is used so that the simple name nested can be used in place of outside::middle::inside.

*
************************************************************************/


// This example illustrates a typedef used to simplify
// a nested class name.

#include <iostream.h>

class outside {
public:
      class middle {
      public:
            class inside {
                  private:
                        int a;
                  public:
                        inside(int a_init = 0): a(a_init) {}
                        void printa();
            };
      };
};

typedef outside::middle::inside nested;

void nested::printa() {
      cout << "Here is a " << this->a << endl;
      }

void main() {
      nested n(9);
      n.printa();
}