C++ Tutorial/Class/protected inheritance

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Inherit base as protected

<source lang="cpp">#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;

}</source>

120 10 12