hurcan solter wrote:
A(){}
In the case "mprm" is undefined. Write " A():mprm(0){} "
well my compiler says that 'A' is not a base class of 'C' so i assume
you can only initialize your immediate base class(why?),
Because immediate base class already initialize all other base classes.
Each base class does not know any about own derived, so do init. Do you
want to initialize twice? Or do you want to know all base classes of
the creating class?
Does virtual inheritance guarantee only one 'A' is created?
Virtual inheritance guarantees, that class A will be initialized by
constructor of real class of creating object, not by constructor of any
its base classes _where_ class A declared as virtual too.
It is similar to virtual members, which are guarantee, that compiler
will call member of real class of object, not member of class of
pointer or reference.
Virtual inheritance turn constructor of class A as virtual member, so
in each class with the virual base, you must write concrete ctor of
virual base, but compiler will call concrete ctor, declared only in
ctor of real class of creating object.
It can be more questions here, but virtual inheritance is enough rare
used, and in most cases (especially for novice) the kind of inheritance
can be replaced by "adapter" design pattern. Note, that ordinary
inheritance in most cases can be replaced by composition too and the
last is better.
It is seems to me, that virtual inheritance is "bad" only as
"inheritanc e", not as "virtual" or "multiple".