c++ nested class experiment

#include
class Outer{
   int m_o;
   public:
   class Inner   {
      public:
        int m_i;
        Inner(){m_i=999;}
        Inner(Outer & m_outer, int x){
           m_outer.m_o = x; //against c++98
        }
   };
   Outer(int y)   {
       cout <m_inner.m_i<<" <—- this field is no-arg constructed.n";
       m_inner.m_i = y;
   }
   void Display()   {
       using namespace std;
       cout << m_o << endl
            << m_inner.m_i << endl;
   }
   Inner m_inner;
};
int main(){
   Outer    objOut(10); //inner == 10
   Outer::Inner objIn(objOut, 5); // objIn discarded, but objOut modified to 5
   objOut.Display();
   cin.get();
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s