Inherit base as protected : protected inheritance « Class « C++ Tutorial






#include <iostream>
using namespace std;

class base {
protected:
  int i, j;
public:
  void setij(int a, int b) { i=a; j=b; }
  void showij() { cout << i << " " << j << "\n"; }
};


class derived : protected base{
  int k;
public:
  void setk() { 
    setij(10, 12); 
    
    k = i*j; 
  }

  void showall() { 
     cout << k << " "; 
     showij(); 
  }
};

int main()
{
  derived ob;

  ob.setk(); 
  ob.showall();

  return 0;
}
120 10 12








9.13.protected inheritance
9.13.1.Inherit base as protected