标签:c++ int protected com pre vat cout 特点 span
1 //public继承特点:基类中公有成员和保护成员将分别作为派生类的公有成员和保护成员 2 //private继承特点:基类中公有成员和保护成员将分别作为派生类的私有成员 3 //protected继承特点:基类中公有成员和保护成员将分别作为派生类的保护成员 4 //下面是public继承举例 5 #include<iostream.h> 6 class A{ 7 private: 8 int a1; 9 protected: 10 int a2; 11 public: 12 int a3; 13 A(int x1,int x2,int x3){ 14 a1=x1; 15 a2=x2; 16 a3=x3; 17 } 18 ~A(){} 19 }; 20 21 class B:public A{ 22 private: 23 int b1; 24 protected: 25 int b2; 26 public: 27 int b3; 28 B(int x1,int x2,int x3,int y1,int y2,int y3):A(x1,x2,x3){ 29 b1=y1; 30 b2=y2; 31 b3=y3; 32 } 33 ~B(){} 34 35 void Print()const{ 36 //cout<<"a1="<<a1<<endl;//非法 37 cout<<"a2="<<a2<<endl; 38 cout<<"a3="<<a3<<endl; 39 cout<<"b1="<<b1<<endl; 40 cout<<"b2="<<b2<<endl; 41 cout<<"b3="<<b3<<endl; 42 } 43 }; 44 45 void Show(B &myB){ 46 //cout<<"myB.a1="<<myB.a1<<endl;//非法 47 //cout<<"myB.a2="<<myB.a2<<endl;//非法 48 cout<<"myB.a3="<<myB.a3<<endl; 49 //cout<<"myB.b1="<<myB.b1<<endl;//非法 50 //cout<<"myB.b2="<<myB.b2<<endl;//非法 51 cout<<"myB.b3="<<myB.b3<<endl; 52 } 53 54 int main(){ 55 return 0; 56 }
标签:c++ int protected com pre vat cout 特点 span
原文地址:https://www.cnblogs.com/Tobi/p/9249830.html