Inner and Outer

#include <iostream>
using namespace std;

class outer
{
  public:
  int x;
  void get()
  {
    cin>>x;
  }
 
  class inner
  {
    private:
    int y;
    public:
    void get()
    {
      cin>>y;
    }
    void sum()
    {
      outer k;
      k.get();
      cout<<k.x+y;
    }
  };
};
       main()
      {
        outer::inner b;
         b.get();
        b.sum();
       

       }

3 comments:

  1. This code is slightly wrong, the rectified version is here:
    #include
    using namespace std;

    class outer
    {
    public:
    int x;
    void get()
    {
    cin>>x;
    }

    class inner
    {
    private:
    int y;
    public:
    void get()
    {
    cin>>y;
    }
    void sum()
    {
    outer k;
    k.get();
    cout<<k.x+y;
    }
    ;
    };
    };
    int main()
    {
    outer::inner b;
    b.get();
    b.sum();
    return 0;
    }

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete