protected inheritance : Protected « Class « C++






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

1.Inheriance for protected member Inheriance for protected member
2.Inherit base as protectedInherit base as protected
3.Demonstrate protected members. Demonstrate protected members.