how to pass arguments to the base classes of a derived class by modifying the preceding program : Derived « Class « C++






how to pass arguments to the base classes of a derived class by modifying the preceding program

  
#include <iostream>  
using namespace std;     

class X {  
protected:  
  int a;  
public:  
  X(int i);  
};  
     
class Y {  
protected:  
  int b;  
public:  
  Y(int i);  
} ;  
     
class Z : public X, public Y {  
public:  
  Z(int x, int y);  
  int make_ab(void);  
} ;  
     
X::X(int i)  
{  
  a = i;  
}  
     
Y::Y(int i)  
{  
  b = i;  
}  
     
Z::Z(int x, int y) : X(x), Y(y)  
{  
  cout << "initializing\n";  
}  
     
int Z::make_ab(void)  
{  
  return a*b;  
}  
     
main(void)  
{  
  Z i(10, 20);  
     
  cout << i.make_ab();  
     
  return 0;  
}
  
    
  








Related examples in the same category

1.A base pointer to access derived objectsA base pointer to access derived objects
2.Demonstrate pointer to derived class.Demonstrate pointer to derived class.
3.Simple class with its derived classSimple class with its derived class
4.call constructor from parent for three level extending
5.Using pointers on derived class objects.