一个程序结果题,不太明白结果的输出,可以指导一下吗,谢谢,大神
#include <iostream>using namespace std;
class A
{
public:
A(char i){cout<<"A's cons."<<i<<endl;}
~A(){cout<<"A's des."<<endl;}
};
class B:virtual public A
{
public:
B(char i,char j):A(i){b = j; cout<<"B's cons."<<j<<endl;}
~B(){cout<<"B's des."<<b<<endl;}
private:
char b;
};
class C:virtual public A
{
public:
C(char i,char j):A(i)
{
cout<<"C's cons."<<j<<endl;
}
~C(){cout<<"C's des."<<endl;}
};
class D:public B,public C
{
public:
D(char i,char j,char k,char s,char m,char n)
:C(k,s),B(i,j),A(i),aa(m){cout<<"D's cons."<<endl;}
~D(){cout<<"D's des."<<endl;}
private:
A aa;
};
void main()
{
D obj('a','b','c','d','e','f');
}
这个程序结果分析不明白,为什莫输出A,以后又输出B,他们的输出顺序不应该是按照声明的顺序输出吗,
我的想法是先A,C,B,A
求指导,谢谢