puzzlecracker wrote:
OK, I actually [implicitly ]meant the case of multiple inheritance,
particularly case of 'dirty diamond'. How does the virtuality keeps
only one copy of the base ? Can you give low and high level overview,
any relevent examples... Thanks a bunch
(a) Please don't top-post.
(b) I am not sure what's low and high level overview, to be honest with
you. If the compiler encounters a virtual base class in a hierarchy of
a particular UDT, it generates a layout where a subobject of that base
class is represented only once. How it does that is not really defined
in the language. If you need to learn how your compiler does that, you
can always cast the most derived class pointer to the virtual base class
and see the difference in the pointer values, which should give you some
idea on where in the derived class object the virtual base resides. IOW,
experiment, and you shall figure out the low level stuff.
(c) If the same class is inherited from both virtually and non-virtually
in the same hierarchy, only the virtual part of it is merged into a single
instance:
struct A {}; struct B : virtual A {}; struct C : A {};
struct D : virtual A {};
struct X : B, C, D {};
Here, every 'X' will have two instances of 'A': C::A and the virtual one,
not one and not three.
Victor