#include<iostream> using namespace std; class Member { public: Member() { cout<<"Member created"<<endl; } ~Member() { cout<<"Member destroyed"<<endl; } }; class Base { public: Base() { cout<<"Base created"<<endl; } ~Base() { cout<<"Base destroyed"<<endl; } }; class Derived:public Base { public: Derived() { cout<<"Derived created"<<endl; } ~Derived() { cout<<"Derived destroyed"<<endl; } private: Member m; }; int main(int argc,char *argv[]) { Derived d; return 0; }运行结果:
Base created
Member created
Derived created
Derived destroyed
Member destroyed
Base destroyed
C++ Primer Plus学习笔记之继承类的初始化顺序,布布扣,bubuko.com
原文:http://blog.csdn.net/cstopcoder/article/details/24935127