Re: ambiguity in diamond inheritance
On 8 mar, 02:23, karthikbalaguru <karthikbalagur...@gmail.com> wrote:
On Mar 8, 2:16 am, happyasaclam...@gmail.com wrote:
On Mar 6, 8:34 pm, karthikbalaguru <karthikbalagur...@gmail.com>
wrote:
I understand the Diamond Problem and the solution of
"Virtual Inheritance" that is used to overcome ambiguity.
But, i wonder why should the Diamond problem arise. This
should be taken care by C++ internally and resolved. Why
C++ could not handle it internally without asking us to do
the 'virtual inheritance'?
Read my example above and consider this:
d.C::f() prints out 50
d.B::f() prints out 30
What should d.f() print out?
Should the compiler just guess which one you meant? Or are
you asking why non-virtual inheritance is the default?
Yes, i am asking why non-virtual inheritance is the default.
Mainly history, I suspect. Non-virtual inheritance has some
performance impacts, and is rarely needed at the application
level (and when it is needed there, it's easy to determine
where, and explicitly declare it). It's true, however, that far
too many frameworks use non-virtual inheritance where virtual
would be required: when in doubt, inheritance should be virtual
(which argues for virtual inheritance being the default).
--
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