#include <iostream>
using namespace std;
class BaseClass {
int x;
public:
void setx(int n) {
x = n;
}
void showx() {
cout << x << '\n';
}
};
// Inherit BaseClass as private.
class DerivedClass : private BaseClass {
int y;
public:
void setxy(int n, int m) {
setx(n); // setx is accessible from within DerivedClass
y = m;
}
void showxy() {
showx(); // showx is accessible from within DerivedClass
cout << y << '\n';
}
};
int main()
{
DerivedClass ob;
ob.setxy(10, 20);
ob.showxy();
return 0;
}
|