protected inheritance
#include <iostream>
using namespace std;
class base
{
protected:
int i, j;
public:
void setij(int a, int b){
i=a;
j=b;
}
void showij(void) {cout << i << " " << j << endl;}
};
class derived : protected base
{
private:
int k;
public:
void setk(void){
setij(10,12);
k = i * j;
}
void showall(void){
cout << k << " ";
showij();
}
};
int main(void){
derived object;
object.setk();
object.showall();
}
Related examples in the same category