虚基类的问题
书上一个程序:#include<iostream>
//
using namespace std;
class B0{
public:
int nV0;
void fun(){cout<<"Member of B0"<<endl;}
B0(int n){nV0=n;cout<<"B0 "<<nV0<<endl;}
//private:
};
class B1: virtual public B0{
int nV1;
public:
B1(int a):B0(a){nV1=a;cout<<"B1 "<<nV1<<endl;}
//void fun(){cout<<"Member of B1"<<endl;}
};
class B2:virtual public B0{
int nV2;
public:
B2(int a):B0(a){nV2=a;cout<<"B2 "<<nV2<<endl;}
// void fun(){cout<<"Member of B2"<<endl;}
};
class B3{
int nV3;
public:
B3(int a){nV3=a;cout<<"B3 "<<nV3<<endl;}
//private:
};
class D1: public B1,public B2,public B3{
int nVd;
B3 b3;
B2 b2;
public:
void fun(){cout<<"Member of D1"<<endl;}
D1(int a):B0(a),B1(a+1),B2(a+2),b3(a+3),B3(a+4),b2(a+5){}
};
int main()
{D1 d1(3);
getchar();
}
运行结果:
B0 3
B1 4
B2 5
B3 7
B3 6
B0 8 //请问这一行是怎么回事?
B2 8