Hello all,
The code example below has proper behavior (of course), but I'm trying to
understand how the behavior is brought about. Specifically, what happens to
B's and C's initialization of A??? Is it just ignored even though it
explicitly appears in the code?
Thanks,
Dave
#include <iostream>
using namespace std;
class A
{
public:
A(int d): data(d)
{
cout << "data initialized to " << d << endl;
}
private:
int data;
};
class B: virtual public A
{
public:
B(int d): A(d)
{
}
};
class C: virtual public A
{
public:
C(int d): A(d)
{
}
};
class D: public B, public C
{
public:
D(int d): A(d), B(d + 1), C(d + 2)
{
}
};
int main(void)
{
// Displays "data initialized to 1"
D foo(1);
return 0;
}