Q:

How can I call methods within a nested class using new()?

Right now, I have a nested class as so:
class Outer{

public:
    class Inner{

    public:
        void display(){
             cout << "You are in inner class" << endl;
        }
     };
     void display(){
         cout << "You are in outer class" << endl;
     }
};

I have to create an instance of each class Outer and Inner so I can invoke each of their display() methods. I have to use new in order to invoke them as part of my requirement. I can invoke the Outer class fine and point to its method as so:
Outer *pOuter = new Outer();
pOuter->display();

But, I'm having troubles doing the same to the Inner class. I've tried:
 Outer:Inner *pInner = new Outer:Inner();
 pInner->display();

but, that doesn't work. So I'm wondering what I can do to invoke the inner method while using new?

A:

Use the fully qualified path:
Outer::Inner* p = new Outer::Inner;
p->display();
delete p;

Without pointers:
Outer::Inner o;
o.display();

Or mark the function static and call as:
Outer::Inner::display();

That being said, as-is this is better suited for a (Outer) namespace instead of a class.

