In the next code, building a C class starts with initializing A then B1 and then B2 and at last C class. However, when initializing B1 and B2, the debugger ignored the initialization of A(1) and A(2) (that appear on the intialization list of B1 and B2 in this order) but didn't ignore the initialization of B2(3) at C initialization list.
Why is that?
Thanks in advance.
Here is the code:
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) {}
};
int _tmain(int argc, _TCHAR* argv[])
{
C* c = new C();
return 0;
}
C.