file://定义基类A class A { public: A() { cout<<"类A的构造函数!"< A(int a) { Aa = a, aa = a, aaa = a; } void APRint() { cout<<"类A打印自己的private成员aa:"< int Aa; private: int aa; protected: int aaa; };
file://定义由基类A派生的类B class B : public A { public: B() { cout<<"类B的构造函数!"< B(int i, int j, int k); void Bprint() { cout<<"类B打印自己的private成员bb和protected成员bbb:"< void B_Aprint() { cout<<"类B的public函数访问类A的public数据成员Aa:"< cout<<"类B的public函数访问类A的protected数据成员aaa:"< GetAaaa(); GetAaaa1();} private: int bb; void GetAaaa() { cout<<"类B的private函数访问类A的public数据成员Aa:"< cout<<"类B的private函数访问类A的protected数据成员aaa:"< protected: int bbb; void GetAaaa1() { cout<<"类B的protected函数访问类A的public数据成员Aa:"< cout<<"类B的protected函数访问类A的protected数据成员aaa:"< };
file://基类B的构造函数,需负责对基类A的构造函数的初始化 B::B(int i, int j, int k):A(i), bb(j), bbb(k) {}