in the following code:
class A
{
public:
int x;
A(int x):x(x){}
};
class B: public virtual A
{
public:
B(int x):A(x){}
};
class C: public virtua
Virtual base classes are only initialised by the most-derived class. That is, if create an instance of D
in your example, A
will only be initialised by its occurence in the mem-initialiser list of D
. Its occurence in the mem-initialiser lists of B
and C
is simply ignored.
That is also why you have to initialise A
in D
: A
doesn't have a default ctor, so D
must know how to initialise it.