/**  show how inheritance works using indirect references
     and private class sections
**/

#include <iostream.h>

class parent
{
   private:
     int mine;
   public:
     parent(int x = 0) 
     {
       mine = x;
       cout << endl << "create parent "<< mine << endl;
     }
     ~parent() { cout << endl << "Destroy parent " << mine << endl;}
     void show_all(void) {cout <<endl << "show " << mine << endl;}
     void add(int x) { mine = mine + x;}     
};


class child: public parent
{
  private:
    int his;
  public:
    child(int x = 0): parent(x+3) 
    {
      his = x;
      cout << endl << "create child " << his << endl;
      parent::show_all();
    }
    ~child() {cout << endl << "Destroy child " << his << endl;}
    void show_all(void) {cout << endl << "show kid " << his << endl;}
};



void main(void)
{
  parent mom, dad(10);
  child kid(3);

  mom.show_all();
  dad.show_all();
  mom.add(10);
  dad.add(10);
  mom.show_all();
  dad.show_all();
  kid.show_all();
} 

//output from the above program

create parent 0
create parent 10
create parent 6
create child 3
show 6

show 0
show 10

show 10
show 20
show kid 3

Destroy child 3
Destroy parent 6
Destroy parent 20
Destroy parent 10