1 //Public inheritance features: the common members and protected members of the base class will be the public and protected members of the derived class, respectively2 //Private Inheritance Features: Public members and protected members in base classes are private members of derived classes, respectively3 //protected Inheritance Features: Public members and protected members in a base class are protected members of the derived class, respectively4 //Here is an example of public inheritance5#include <iostream.h>6 classa{7 Private: 8 intA1;9 protected:Ten intA2; One Public: A intA3; -AintX1,intX2,intx3) { -a1=X1; theA2=x2; -a3=X3; - } -~A () {} + }; - + classB: Publica{ A Private: at intB1; - protected: - intB2; - Public: - intB3; -BintX1,intX2,intX3,intY1,intY2,inty3): A (x1,x2,x3) { inb1=Y1; -B2=Y2; tob3=Y3; + } -~B () {} the * voidPrint ()Const{ $ //cout<< "a1=" <<a1<<endl;//illegalPanax Notoginsengcout<<"a2="<<a2<<Endl; -cout<<"a3="<<a3<<Endl; thecout<<"b1="<<b1<<Endl; +cout<<"b2="<<b2<<Endl; Acout<<"b3="<<b3<<Endl; the } + }; - $ voidShow (B &MyB) { $ //cout<< "myb.a1=" <<myB.a1<<endl;//illegal - //cout<< "myb.a2=" <<myB.a2<<endl;//illegal -cout<<"myb.a3="<<myB.a3<<Endl; the //cout<< "myb.b1=" <<myB.b1<<endl;//illegal - //cout<< "myb.b2=" <<myB.b2<<endl;//illegalWuyicout<<"myb.b3="<<myB.b3<<Endl; the } - Wu intMain () { - return 0; About}
C + + Learning (14)