#include <iostream>
using namespace std;
class BaseClass1 {
protected:
int i;
public:
BaseClass1(int x) {
i =x;
cout << "Constructing BaseClass1\n";
}
~BaseClass1() {
cout << "Destructing BaseClass1\n";
}
};
class BaseClass2 {
protected:
int k;
public:
BaseClass2(int x) {
k = x;
cout << "Constructing base2\n";
}
~BaseClass2() {
cout << "Destructing base2\n";
}
};
class DerivedClass: public BaseClass1, public BaseClass2 {
public:
DerivedClass(int x, int y): BaseClass1(x), BaseClass2(y) {
cout << "Constructing DerivedClass\n";
}
~DerivedClass() {
cout << "Destructing DerivedClass\n";
}
void show() {
cout << i << " " << k << endl;
}
};
int main()
{
DerivedClass ob(3, 4);
ob.show();
return 0;
}
|