http://www.cnblogs.com/lixiaohui-ambition/archive/2012/07/13/2589716.html

g++ test.cpp -o test

base a construct 1

base a1 construct 2

base b construct 3

base a construct 4

base a2 construct 5

base c construct 6

base c destruct5

base a2 destruct4

base a destruct3

base b destruct2

base a1 destruct1

base a destruct0

base a construct 1

base a1 construct 2

base b construct 3

base a2 construct 4

base c construct 5

base a1 destruct4

base a destruct3

#include <iostream>

using namespace std;

int n;

class a{

public:

a(){cout<<"base a construct "<<(++n)<<endl;};

virtual ~a(){cout<<"base a destruct"<<(--n)<<endl;}; //1

};

class a1: public virtual a

{

public:

a1(){cout<<"base a1 construct "<<(++n)<<endl;};

~a1(){cout<<"base a1 destruct"<<(--n)<<endl;};

};

class a2: public  virtual a

{

public:

a2(){cout<<"base a2 construct "<<(++n)<<endl;};

~a2(){cout<<"base a2 destruct"<<(--n)<<endl;};

};

class b : public a1{

public:

b(){cout<<"base b construct "<<(++n)<<endl;};

~b(){cout<<"base b destruct"<<(--n)<<endl;};

};

class c : public b,public a2{

public:

c(){cout<<"base c construct "<<(++n)<<endl;};

~c(){cout<<"base c destruct"<<(--n)<<endl;};

};

int  main()

{

n = 0;

a1* t = new c();

delete t;

return 0;

}