Re: order of constructor execution...
On Dec 19, 5:18 pm, Rahul <sam_...@yahoo.co.in> wrote:
[...]
And moreover, i didn't get the reason as why virtual bases
have to be initialized first...
Who should initialize it?
In your precise example, one could argue that C should, since
it's not explicitly known any higher. But what happens then if
you derived from B:
class F : public B, public virtual E
? One could imagine a rule in which the compiler constructed
the inheritance graph, and then initialized the virtual base in
the highest node which included all possible paths to it, but
this would be considerably more complicated, both to implement
and to understand, since it would result in different virtual
bases being initialized in different classes in the hierarchy.
(In the above example, for example, E would be initialized by F,
but D would still be initialized by C. And what does it buy us?
In practice, virtual base classes are almost always empty, and
only have default constructors (since they have no data to
initialize).
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34