Hi 100,
100 said:
Actually calling ToString for pointer or reference of type FooBar is error
in C++ anyway. The program won't compile.
You have to cast to one of the base classes.
FooBar fb = new FooBar();
((Foo*)fb)->ToString();
or one can override ToString in FooBar and call the ToString method of the
base class of choice.
This is in case that the classes don't implicitly inherit from a common
class (Object)
In my example both Foo and Bar *do* inherit from the same base class
(Object). Hence the ToString implementations are overrides. And if you cast
to the base class and call ToString, then the compiler will have to choose
either the Foo or Bar implementation of ToString. Even though the behavior
is predictable, it still seems unnatural (to me) that a significant behavior
change could result from simply re-ordering the inheritance list.
If we have this Object class in this case programmers have two choices to
use virtual or non-virtual inheritance.
Anyway the laguage has standard constructions to resolve any ambiguities.
You know, this brings up something I hadn't even thought of before. To
virtually inherit or not and the implications of that choice on behavior and
performance.
How "yucky" is the code depends on how good is the design. I can write
really "yucky" code without using multiple inheritance
![Wink ;) ;)](/styles/default/custom/smilies/wink.gif)
))))
Agreed.
Even though multipile inheritence needs to be used carefully it is verry
useful and I miss it once in a while.
I'll admit I'm torn on this subject. I've never been a fan of the idea
of removing or preventing something in a language just because *some* people
will misuse/abuse it. There are also times when I think it would be nice to
use MI. On the other hand, I appreciate a "clean", straightforward language
that encourages me to do "the right thing". To me, MI seems counter to those
ideals.
To summarize, I don't think MI is bad or useless. I do think it's a lot
less trivial than many people realize.
Regards,
Dan