C
chrolson
For the following classes, why is the output 1 instead of 10?:
class Top
{
public:
Top():a(1){}
Top(int arg):a(arg){}
virtual ~Top(){}
int a;
};
class Left : virtual public Top
{
public:
Left():b(2){}
int b;
};
class Right : virtual public Top
{
public:
Right(): c(3), Top(10){}
int c;
};
class Bottom : public Left, public Right
{
public:
Bottom():d(4){}
int d;
};
int main()
{
Bottom* bottom = new Bottom();
Right *right = bottom;
cout << "right->a: " << right->a << endl;
return 0;
}
class Top
{
public:
Top():a(1){}
Top(int arg):a(arg){}
virtual ~Top(){}
int a;
};
class Left : virtual public Top
{
public:
Left():b(2){}
int b;
};
class Right : virtual public Top
{
public:
Right(): c(3), Top(10){}
int c;
};
class Bottom : public Left, public Right
{
public:
Bottom():d(4){}
int d;
};
int main()
{
Bottom* bottom = new Bottom();
Right *right = bottom;
cout << "right->a: " << right->a << endl;
return 0;
}