- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
I'm virtually the first!
Admin
And now all your inheritance is in a vtable, and requires indirection.
Admin
It's actually worse than that, because the construction of a virtual-inheritance object is ... fraught. If the base class is totally non-concrete, you can sort of get away with it, except that in that case the virtual inheritance has no purpose.
If, on the other hand, the base class has stuff in it, then it's necessary to have ways for methods of the derived class to find the base object because it might not be adjacent to the derived part of the combination, and that imposes a performance penalty (even though it might be small). It gets worse as you put in more layers of chained virtual-virtual-virtual inheritance.
Admin
I might be in the minority but I'm ok with multiple inheritance. C++ may not be perfect but not having it is a pain. Languages do things like mix ins and C#'s new feature of default implementation of an interface method. It's basically like saying, we're ok with MI but no virtual method.
Admin
With C you can shoot yourself in the foot, but C++ comes with a mini-gun capable of obliterating your anatomy like an A10 Warthog.
Admin
The first OO language I used a significant amount was Common Lisp with CLOS, and before that Lisp Machine Lisp with Flavors. They have multiple inheritance, and all inheritance is virtual (I suppose you could define a new metaclass that implements a different inheritance scheme, so I'm just talking about the standard behavior). No one considered it much of a problem. At worst it complicates the algorithm for determining the total order of the class hierarchy based on the partial orders of each inheritance step, although in practice you rarely depend on the specific order.
Admin
+10!!! I once inherited (no pun intended) a system that had an inheritance hierarchy more than 30 classes deep. Basically, each subclass was a method in a straight-line call chain. Yeech.
Admin
You have to be an old-timer like me to know what an El Camino is without looking it up. Hey! Get off my lawn!
Admin
Interface inheritance is pretty fundamentally different from class inheritance; e.g. the diamond problem does not exist during interface inheritance. Mixins are an orthogonal concept. It makes the most sense to allow classes to inherit from zero or one classes, to implement zero to many interfaces, and to include zero to many mixins.
The problem with C++ is that these separate concepts (and others) are all treated as the same kind of nail by its big inheritance hammer. In C++ interfaces and mixins only exist by local convention, so it is difficult if not impossible to enforce the constraints that these concepts require. Foot shooting ensues.
I recommend implementing mixins with a component model rather than with inheritance.
Admin
There's no such thing as interface inheritance. Interface implementation is different than class inheritance sure, but there are many examples where multiple inheritance makes conceptual sense. Regarding mix ins, that's what I've basically been doing, however awkwardly the resulting code ends up looking.
Admin
I'm not sure about C or C++ but interface inheritance does exist. C# for example allows interfaces to be inherited
Admin
Correct, I misspoke on that
Admin
"Where does ElCamino get its drive() function from?"
The compiler forces you to disambiguate and everyone gets on with their lives?
Oh wait no, the Gang of Four don't like it, so we all have to pretend it's way harder than that and hobble every modern language.
Admin
Or you're a fan of The Black Keys.
Admin
Back in the day I worked for a company with everything written in C++ where they had various "interfaces" as base classes and implementation as base classes and multiple inheritance for the actual classes used (as advocated by Stroustrup at the time). The system was large and mature and had lots of customers and deployments. Of course I got to the point where I needed to inherit from two of these actual classes to do what I needed to do. All hell broke loose and nothing worked. I found out what was going wrong and "discovered" the diamond problem for myself and realized that I could solve my problem easily: all I had to do was go back through (nearly) every class in the library and mark the inheritance as virtual and re-build everything and re-release everything. Which never happened, of course. At the time I wished that someone, back in time, had religiously marked all the inheritance as virtual so that my problem would have been easily solved. (Event though 90% of the code had been written before virtual inheritance existed in C++.)
Admin
Back in the day I worked for a company with everything written in C++ where they had various "interfaces" as base classes and implementation as base classes and multiple inheritance for the actual classes used (as advocated by Stroustrup at the time). The system was large and mature and had lots of customers and deployments. Of course I got to the point where I needed to inherit from two of these actual classes to do what I needed to do. All hell broke loose and nothing worked. I found out what was going wrong and "discovered" the diamond problem for myself and realized that I could solve my problem easily: all I had to do was go back through (nearly) every class in the library and mark the inheritance as virtual and re-build everything and re-release everything. Which never happened, of course. At the time I wished that someone, back in time, had religiously marked all the inheritance as virtual so that my problem would have been easily solved. (Event though 90% of the code had been written before virtual inheritance existed in C++.)
Admin
Do you also know El Camino Bignum? What was named with this, why was it named with this, and what was the real name? Oh yes, pun intended. :-)
Admin
Could someone explain / re-phrase the part about "at the same time" in "... implements the shoot() method at the same time". Probably because being a non-native speaker, it is hard to relate "at the same time" to anything the sentence ?