- 构造函数调用顺序:先调用基类的构造函数,再调用对象成员构造函数,最后调用派生类的构造函数
- 析构函数的调用顺序:先调用派生类的构造函数,再调用对象成员构造函数,最后调用基类的构造函数;(与构造函数调用顺序相反)
#include "stdafx.h" #include <iostream> using namespace std; class Hello { public: Hello() { cout << "Hello 构造函数" << endl; } }; class Sup { public: Sup() { cout << "Sup 构造函数!" << endl; } }; class Son : public Sup { public: Son() { cout << "Son 构造函数" << endl; } private: Hello a; }; int _tmain(int argc, _TCHAR* argv[]) { new Son(); return 0; }