[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: On C++ multiple inheritance
Miguel A. Osorio wrote:
Hey people,
I'm currently in the process of doing some changes to my renderer
and I'll probably adding some new classes into the existing hierarchy.
At this time, I do make some *light* use of multiple inheritance and
haven't had any problems with it yet, nor do I detect any problems
arising from changes or additions I'll be making to the hierarchy.
*But*, I have noticed that quite a large number of programmers
declare multiple inheritance as something to be "avoided like the
plague", and although I can relate to that if I imagine a badly
designed hierarchy using that mechanism, I'm not really sure of the
reasons behind negative arguments like that.
Multiple inheritance can be dangerous in C++ because it can cause subtle
bugs that are very hard to catch.
Most of these bugs have to do with wrong pointer offsetting when casting
from one of the inherited classes
to the parent cast and vice versa.
If you only use pure virtual abstract classes (the interfacing idea like
already presented in this list)
then the use of multiple inheritance is not that bad.
Greetings,