构造函数的调用次序
为什么结果是CBase1 classCBase2 class
CDerive2 class
CBase2 cass
CDerive1 class
CTop class
而不是
CBase1 class
CBase2 class
CDerive2 class
CBase1 class
CBase2 cass
CDerive1 class
CTop class
#include<iostream.h>
class CBase1
{
public:
CBase1()
{cout<<"CBase1 class!\n";}
};
class CBase2
{
public:
CBase2(){cout<<"CBase2 class!\n";}
};
class CDerive1:public CBase2,virtual public CBase1
{
public:
CDerive1()
{cout<<"CDerivel class\n";}
};
class CDerive2:public CBase2,virtual public CBase1
{
public:
CDerive2()
{cout<<"CDerive2 class\n";}
};
class CTop:public CDerive1,virtual public CDerive2
{
public:
CTop()
{cout<<"CTop class\n";}
};
void main()
{ CTop topobj; }