Init member variables from base class
#include <iostream>
using namespace std;
class BaseClass {
int i, j;
public:
BaseClass(int x, int y) {
i = x;
j = y;
}
void showij() {
cout << i << ' ' << j << '\n';
}
};
class DerivedClass : public BaseClass {
int k;
public:
DerivedClass(int a, int b, int c) : BaseClass(b, c) {
k = a;
}
void show() {
cout << k << ' '; showij();
}
};
int main()
{
DerivedClass ob(1, 2, 3);
ob.show();
return 0;
}
Related examples in the same category