Why isn't multiple inheritance very useful?

Discussion in 'C++' started by Vla, Jan 20, 2005.

  1. Vla

    Vla Guest

    why did the designers of c++ think it would be more useful than it turned
    out to be?
    Vla, Jan 20, 2005
    1. Advertisements

  2. I guess you haven't read "Modern C++ Design"...
    Victor Bazarov, Jan 20, 2005
    1. Advertisements

  3. Why do people asked loaded rhetorical questions in the most innocent
    manner possible?
    Joseph Turian, Jan 20, 2005
  4. Vla

    Howard Guest

    I don't know. Want me to ask them? I've got their cell phone numbers here
    somewhere... :)

    Howard, Jan 20, 2005
  5. Vla

    White Wolf Guest

    Why? Isn't multiple inheritance very useful?
    White Wolf, Jan 20, 2005
  6. Vla

    Vla Guest

    Whether true or not, it certainly is, or at least was, a widely held belief,
    that multiple inheritance doesn't turn out to be of much practical use.
    Perhaps in the couple years since I last heard that (or read it) "modern c++
    design" has evolved to include widespread use of multiple inheritance. My
    question would then become "why did it take so long for multiple inheritance
    to catch on".

    Unless you want to deny that multiple inheritance was ever considered to be
    a slight disappointment regarding its practical use.
    Vla, Jan 20, 2005
  7. Multiple inheritance is very useful.
    Beware the Diamond pattern.
    Read the FAQ about inheritance.
    Consult "Design Patterns" about multiple inheritance.

    Thomas Matthews

    C++ newsgroup welcome message:
    C++ Faq: http://www.parashift.com/c++-faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
    http://www.sgi.com/tech/stl -- Standard Template Library
    Thomas Matthews, Jan 21, 2005
  8. Vla

    red floyd Guest

    And in years past, it was a widely held belief that the world was flat.
    Your point?

    Read the book "Modern C++ Design", by Andrei Alexandrescu to see what
    Victor was talking about.
    red floyd, Jan 21, 2005
  9. Vla

    Andy Guest

    its funny how ppl just insult others or try to be funny because they dont
    like the question they asked. The guy asked a question if you dont know
    the answer are feel its stupid then dont reply to it.
    Andy, Jan 21, 2005
  10. Vla

    Zorro Guest

    I am not sure whether you guys are joking, or these are serious
    concerns. Multiple inheritance is not possible for virtual machines
    with the technology underlying Smalltalk, Java and C#. It is easy to
    see who spreads the word that multiple inheritance is complicated. The
    question is, who is it complicated for? The designer of the language or
    the engineer?

    There are many ordinary problems whose implementation becomes
    excessively long, and far from the intuitive view of the problem when
    one is forced to use single inheritance.

    You can find a superset of C++ running on a tiny virtual machine. Visit

    Enjoy it.
    Zorro, Jan 21, 2005
  11. Why do you think the designers of c++ thought it would be more useful
    than it is ?

    BTW - If I was a C++ designer, and I thought back then that multiple
    inheritance would be as useful as I now think it is, I'd be quite happy
    with myself.

    Gianni Mariani, Jan 21, 2005
  12. Vla

    matthias_k Guest

    I think it -is- very useful. I'm not sure who the people are telling you
    it wouldn't be useful. Probably Java enthusiasts. In fact, the lack of
    multiple inheritance in Java can be an annoyance, because you have to
    workaround using interfaces and delegation. It makes your code slower,
    but you end doing the same thing basically.

    By the way, multiple inheritance doesn't even need to be as error prone
    as a lot of people claim. Look at Eiffel or Sather or Objective C, they
    have pretty clever mechanisms to deal with multiple inheritance.

    matthias_k, Jan 21, 2005
  13. That question could prove more difficult to answer than one might think.
    Interface-style MI as supported by Java & C# surely makes things easier
    for language designers and the people who actually implement the
    language. However, a nice side-effect is that easier implementations
    also often perform much better. Specifically, garbage collectors and
    casts are faster in the absence of full MI and that also benefits the
    language users.
    Right. However, both the Java and the CLR/C# teams felt that performance
    is more important than a releatively rarely used language feature,
    which - given that you control the code of all classes you want to
    inherit from - can easily be simulated with intefaces.

    Andreas Huber, Jan 21, 2005
  14. I'm not entirely sure what you mean, and anyway your subject and body
    ask two quite different questions.

    ATMS, multiple inheritance is a relatively complex feature. As such,
    some languages have decided not to include full MI, but offer such
    partial solutions as interfaces and mixins. This was part of the design
    of D:


    "Features to Drop"
    "Multiple inheritance. It's a complex feature of debatable value. It's
    very difficult to implement in an efficient manner, and compilers are
    prone to many bugs in implementing it. Nearly all the value of MI can be
    handled with single inheritance coupled with interfaces and aggregation.
    What's left does not justify the weight of MI implementation."

    As for why MI was included in C++, maybe it was a matter of believing
    that it might come in useful one day, rather than having any particular
    practical uses in mind. And eventually people found uses.

    Now that some languages provide these partial solutions, there is more
    scope for debate over MI's usefulness.

    Stewart Gordon, Jan 21, 2005
  15. Vla

    Pete Becker Guest

    Well, maybe in the sense that these VMs weren't desiged to support
    multiple inheritance. But that's a design decision, not an inherent
    limitation. This reminds me of the assertion I once saw in a Java
    magazine that C++ couldn't have garbage collection because it doesn't
    run in a VM. The two have nothing to do with each other. (Our compiled
    Java implementation doesn't run in a VM, but it does have garbage
    Pete Becker, Jan 21, 2005
  16. Pete Becker wrote:
    The same applies to GC languages that were designed to be complied into
    native code. D is one; can anyone think of others?


    Not to mention that GC engines have been written for C++. The trouble
    is that, since C++ wasn't designed with GC in mind, C++ libraries don't
    tend to get on well with GC engines.

    Stewart Gordon, Jan 21, 2005
  17. Vla

    White Wolf Guest

    There are a billion, they just get less hype than D. xBase++ was one of
    them, but I am sure there are many others.
    White Wolf, Jan 21, 2005
  18. Vla

    Jerry Coffin Guest

    [ ... ]
    Oh, let's see: ML/SML, Algol68, Modula III, Eiffel (after "freezing"),
    BASIC (GC only on strings), a multitude of LISP variants, Simula,
    several SNOBOL 4 variants (e.g. Fastbol), Icon, Haskell, Sather (at
    least sometimes does native compilation, though I'm not sure about
    whether it was really designed with that in mind), etc., ad off-topic
    Jerry Coffin, Jan 21, 2005
  19. Vla

    Zorro Guest

    Andreas, there is a lot of truth in your statements. But think about
    Java does not have enumeration type. It turn out that one actually
    needs it. So, in Java one turns a class into a global namespace by
    declaring everything in it as static. That simulates enumeration.
    However, just because one has MI available, it does not mean that one
    should use it where it makes no sense. But when it is needed,
    simulating it is awkward, just as simulating enumeration is.
    Zorro, Jan 22, 2005
  20. Vla

    Zorro Guest

    Yes Pete, it was a natural design decision for Smalltalk language based
    on the idea used to implement its stack machine. The design here is
    that a super class will be the base for everything.
    So now the question for Java is this. Did they first research the
    language and its suitability for expressing problems, and then they
    made the VM, or, from what they could do with VM, they put a language
    As for garbage collection, it is not easy to just say a few things
    about pointers and make much sense. However, Java garbage collection is
    a consequence of yet another difficult issue. Have you noticed that all
    interpreted languages, and those running on VM do not have pointers? It
    is a lot easier to do garbage collection, and then make a big deal
    about it.
    The use of pointers is extremely difficult. But then, should we trust a
    truck driver to fly a plane, or vice versa? So every engineer has
    his/her favorites and experience.

    Zorro, Jan 22, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.