Re: [gtkmm] Bug 116280



Am Thursday, 17. July 2003 20:21 schrieb Chris Vine:
>
>      A
>
>    _____
>
>   B     B
>
>   C     D
>
>    _____
>
>      E
>
> Here E (the finally derived class) has two Bs unless the inheritance of B
> by C and B by D is virtual (in which case you would not need the
> inheritance of A by B to be virtual, because there is only one B anyway).
>

There is possibly another problem:

The standard says that the finally derived class must call the constructors of 
all inherited virtual objects. It's not enough when the constructor of B 
calls the constructor of virtual A, but also the constructors of C, D and E 
must call it. Otherwise A's default constructor will be called regardless of 
the definition in B's constructor.
This is logical because B's constructor does not know that there are two 
instances of class B. If both would initialize virtual A it could be fatal.
This makes virtual inheritance a problematic feature, because someone who 
derives from a class has to look up the class tree for virtual objects that 
must be initialized with meaningful values. This also makes clear why it is 
in fact only clever to define virtual inheritance for simple classes, that 
only have a default constructor.
This is another argument, why virtual inheritance may be difficult to 
introduce in a existing class tree and may break API. It should also be clear 
that it definitely breaks ABI.

Daniel

> Chris.
>
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]