#includeusing namespace std; class Parent { public: Parent(const char* p) { cout << "父类的构造函数" << p << endl; } void printP() { printf("我是父类函数printP()!n"); } ~Parent() { cout << "父类析构函数" << endl; } protected: int a; int b; private: }; class Child : public Parent { public: Child():Parent("aaa") { a = 0; b = 0; c = 0; cout << "子类的构造函数" << endl; } void printC() { printf("我是子类函数printC()!n"); } ~Child() { cout << "子类析构函数" << endl; } protected: private: int c; }; void playObj() { //Parent p1("ddd"); // 没有基类哪有派生类 Child c1; // 子类先调用父类的构造函数,然后再调用子类自己的构造函数 } void main() { playObj(); system("pause"); }



