Mega Code Archive

 
Categories / C++ / Class
 

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;   }