class A
{
public:
A() { cout<<"Construct A"<
~A() { cout<<"Destruct A"<
void speak() { cout<<"A is speaking!"<
};
class B:public virtual A
{
public:
B() { cout<<"Construct B"<
~B() { cout<<"Destruct B"<
};
class C:public virtual A
{
public:
C() { cout<<"Constuct C"<
~C() { cout<<"Destruct C"<
};
class D:public B, public C
{
public:
D(){ cout<<"Constsruct D"<
~D(){ cout<<"Destruct D"<
};
int main()
{
D *p = new D();
p->speak();
delete p;
}
输出:
Construct A
Construct B
Constuct C
Constsruct D