469,609 Members | 2,252 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

Any use of multiple inheritance?

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++?
Jul 22 '05 #1
5 1946
Morgan Cheng wrote:
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.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting

Jul 22 '05 #2
Actually, class adapter from GoF (see page 141) uses multiple
inheritance.

Also, I advise you to read this interview with Bjarne Stroustrup:
http://www.artima.com/intv/modern.html

Jul 22 '05 #3

"Morgan Cheng" <mo************@gmail.com> wrote in message
news:cp**********@avnika.corp.mot.com...
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."
Jul 22 '05 #4
nt*********@hotmail.com wrote:
Actually, class adapter from GoF (see page 141) uses multiple
inheritance.
Yes. But it is recommended to use object adapter instead of class adapter.
Also, I advise you to read this interview with Bjarne Stroustrup:
http://www.artima.com/intv/modern.html

Jul 22 '05 #5
Take a look at Modern C++ design, it is used elegantly with templates for
Policies.
"Morgan Cheng" <mo************@gmail.com> wrote in message
news:41**************@gmail.com...
nt*********@hotmail.com wrote:
Actually, class adapter from GoF (see page 141) uses multiple
inheritance.

Yes. But it is recommended to use object adapter instead of class adapter.
Also, I advise you to read this interview with Bjarne Stroustrup:
http://www.artima.com/intv/modern.html

Jul 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Graham Banks | last post: by
20 posts views Thread by km | last post: by
22 posts views Thread by Matthew Louden | last post: by
47 posts views Thread by Mark | last post: by
15 posts views Thread by iKiLL | last post: by
7 posts views Thread by Adam Nielsen | last post: by
47 posts views Thread by Larry Smith | last post: by
reply views Thread by Solution2021 | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.