Any use of multiple inheritance?

M

Morgan Cheng

It seems no pattern defined by GoF takes advantage of multiple
inheritance. I am wondering if there is a situation where multiple
inheritance is a necessary solution.

When coding in C++, should multiple inheritance still be avoided?

If yes, why multiple inheritance is introducted into C++?
 
D

Dietmar Kuehl

Morgan said:
It seems no pattern defined by GoF takes advantage of multiple
inheritance. I am wondering if there is a situation where multiple
inheritance is a necessary solution.

There is no situation where mutiple inheritance is *necessary*.
Of course, there is also no situation where inhertiance is
*necessary*. After all, everything we can do with C++ can also
be done with a Turing machine and there is no such thing as
inheritance there.
When coding in C++, should multiple inheritance still be avoided?

Inheritance should be avoided (note the deliberate absence of
"multiple"). You should use inheritance only when it makes your
design simpler. If multiple inheritance makes your design
simpler, you should use multiple inheritance. ... and, yes,
there are indeed some situations where inheritance is the
right way to go. The same applies to multiple inheritance. Just
because the GoF does not use them does not mean that it's
useless.
 
J

jeffc

Morgan Cheng said:
It seems no pattern defined by GoF takes advantage of multiple
inheritance. I am wondering if there is a situation where multiple
inheritance is a necessary solution.

Multiple inheritance can be useful for "mix-in" classes. Or as Stroustrup said
in that interview (I believe he is talking about the same thing) - "you just
want to combine a couple of classes that you happen to have."
 
M

Morgan Cheng

Actually, class adapter from GoF (see page 141) uses multiple
inheritance.
Yes. But it is recommended to use object adapter instead of class adapter.
 
M

Michael

Take a look at Modern C++ design, it is used elegantly with templates for
Policies.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top