Re: C++ multiple inheritance [was Re: [GD-General] Eiffel]
Brought to you by:
vexxed72
From: Thatcher U. <tu...@tu...> - 2002-01-03 16:38:11
|
On Jan 02, 2002 at 11:28 -0800, Jesse Jones wrote: > >I realize that you're advocating a hierarchy that looks like this: > > > >B > >| > >C D A > > \|/ > > E > > > >But I don't think there's a good way to enforce that. > > Nope, and even if you're careful and rigorously distinguish between > main-line and mixin classes it's still possible to accidentally mix > in the same class twice into an inheritance hierarchy. However in > practice I haven't found this too be much of a problem and this > approach neatly sidesteps all of the subtleties and ugliness > associated with virtual inheritance. My point is, *always* using virtual inheritance is the only way to make MI truly safe. Then the subtleties and ugliness are all in the compiler (where they belong). You (and Meyers for that matter) have this backwards -- the "diamond of death" is actually what you want in all the class hierarchies I've come across. If you find yourself wanting non-virtual inheritance, it means you're trying to model a kind of "is-implemented-in-terms-of", which should not be done with inheritance at all. Non-virtual multiple inheritance is a bug in C++. IMHO, of course :) -- Thatcher Ulrich <tu...@tu...> http://tulrich.com |