I have the following structs
struct A
{
int i;
A() { i = 0; }
A(int _i) : i(_i) {}
virtual void f() { cout << i; }
};
struct B1 : virtual A {
B1() : A(1) { f(); }
void f() { cout << i+10; }
};
struct B2 : virtual A {
B2(int i) : A(2) { f(); }
};
struct C : B1, B2 {
C() : B2(3) {}
};
please explain why the following code prints 100: (10+0)
C* c = new C();
I think it should print 1111:
first A() : i = 0
then B1() : i = 1 and prints B1::f()
- 11
then B2() : prints prints B1::f()
- 11
Where I go wrong?
Thanks