#include <iostream>
using namespace std;
class BaseClass {
int i;
public:
void setInt(int num) {
i = num;
}
int getInt() {
return i;
}
};
class derived: public BaseClass {
int j;
public:
void setJ(int num) {
j = num;
}
int getJ() {
return j;
}
};
int main()
{
BaseClass *bp;
derived d;
bp = &d; // BaseClass pointer points to derived object
// access derived object using BaseClass pointer
bp->setInt(10);
cout << bp->getInt() << " ";
return 0;
}
|