Re: Interface implementation
On Jun 14, 3:32 pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
Galian wrote:
Yes, inherit from IA _virtually_ *everywhere*. I.e. make B inherit
from IA virtually and make ITwoInOne inherit virtually.
So this is right way:
class B : public virtual IA
{
};
class NewOne : public virtual B
, public virtual ITwoInOne
{
};
Is this right?
If ITwoInOne inherits from IA, it must also inherit virtually.
If NewOne is the most derived class, on the other hand, virtual
inheritance from B and from ITwoInOne is not necessary, although
it may be a good idea, in case someone later wants to inherit
from it. (In general, unless the inheritance tree is closed,
most inhertance should be virtual.)
If yes, than question: is order of classes for inheritance important?
I mean it is OK if I write first "public virtual ITwoInOne", and than
"public virtual B"?
I think that the order is not significant.
It affects the order in which constructors are called. In the
case of virtual base classes, the constructors are called from
the most derived class, "in the order they appear on a
depth-first left-to-right traversal of the directed acyclic
graph of base classes, where `left-to-right' is the order of
appearance of the base class names in the derived class
base-specifierlist."
It will also typically affect the actual layout, and may have
some effect on runtime, although I can't imagine this being
significant.
Have you tried it? If you
have, and the success depended on the order, could you please share?
If you haven't tried, why?
Note that trying it doesn't tell you anything about the
guarantee. The order you find might be because in the standard,
the order was implementation defined, or unspecified.
Experimentation is usually a pretty poor means of finding out
these sort of things; the poster is doing the right thing in
asking.
--
James Kanze (GABI Software, from CAI) 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