#include<iostream> 2 #include<string> 3 using namespace std; 4 class parent{ 5 protected: 6 int m_a; 7 int m_b; 8 public: 9 int m_c; 10 void set(int a,int b,int c){ 11 m_a = a; 12 m_b = b; 13 m_c = c; 14 } 15 }; 16 class child_A:public parent{ 17 public: 18 void print(){ 19 cout << "m_a=" << m_a << endl; 20 cout << "m_b=" << m_b << endl; 21 cout << "m_c=" << m_c << endl; 22 } 23 }; 24 class child_B:protected parent{ 25 public: 26 void print(){ 27 cout << "m_a=" << m_a << endl; 28 cout << "m_b=" << m_b << endl; 29 cout << "m_c=" << m_c << endl; 30 } 31 }; 32 class child_C:private parent{ 33 public: 34 void print(){ 35 cout << "m_a=" << m_a << endl; 36 cout << "m_b=" << m_b << endl; 37 cout << "m_c=" << m_c << endl; 38 } 39 40 }; 41 class child_D:public child_C{ 42 }; 43 int main(){ 44 //child_A a;//public继承 45 //child_B b;//protected 继承 46 //child_C c;//private继承 47 //a.m_c = 100;//100 48 //b.m_c = 100;//100 49 //c.m_c = 100; 50 //a.print(); 51 //b.print(); 52 //c.print(); 53 //cout << endl; 54 //a.set(1,1,1); 55 //b.set(2,2,2); 56 //c.set(3,3,3); 57 child_D d; 58 d.print(); 59 d.set(1,2,3); 60 return 0; 61 }