Dangers of Multiple Inheritance

Discussion in 'C++' started by Corno, Sep 23, 2003.

  1. Corno

    Corno Guest

    Hi all,

    I know there are quite a few arguments in favor or against MI. I know there
    are a lot of usenet discussions about wether MI is actually needed or not.
    These discussions mention the 'dangers' of MI.
    The problem is; I know that there are dangers concerned with MI and I know
    how I can avoid them, I just don't have a clear idea of what the dangers
    actually are and if they are applicable to to the situations I encounter.
    The only danger I (think I) really understand is the dreaded diamond.
    But there also seems to be an issue with copying and assignment which I
    don't see.
    And is there more danger that I should be aware of? and will these problems
    surface during compiling or runtime?

    Does anybody know a good article specifically about this or else would
    somebody care to explain it to me in this newsgroup?

    TIA,

    Corno
    Corno, Sep 23, 2003
    #1
    1. Advertising

  2. "Corno" <corno@%spam%.dds.nl> a écrit dans le message de
    news:bkpcqk$1mj$...
    > And is there more danger that I should be aware of? and will these

    problems
    > surface during compiling or runtime?


    It is at least partially a case of saying it is dangerous to avoid having to
    implement it in many GC based languages.
    It apparently makes building an efficient GC more difficult to design (not
    impossible, see Eiffel).
    So Java & C# designer replaced it with interfaces (multiple inheritance
    without data) as a workaround.
    Michel de Becdelièvre, Sep 23, 2003
    #2
    1. Advertising

  3. "Corno" <corno@%spam%.dds.nl> wrote in message
    news:bkpcqk$1mj$...
    >
    > I know there are quite a few arguments in favor or against MI. I
    > know there are a lot of usenet discussions about wether MI is
    > actually needed or not.


    MI is "not needed" in the way that classes "aren't needed". That is,
    you can write equivalent programs without it, but the feature makes
    some designs a lot simpler.

    > [...]
    > The only danger I (think I) really understand is the dreaded
    > diamond.


    LOL@"dreaded" The diamond inheritance diagram strikes fear in
    the hearts of coders!

    > But there also seems to be an issue with copying and assignment
    > which I don't see.


    I don't see it either. You have to make sure that all your base
    classes agree on how to copy and assign, but I'm not aware of any
    nasty gotchas.

    > And is there more danger that I should be aware of? and will these
    > problems surface during compiling or runtime?


    One issue to keep in mind is size. Many, if not most compilers will
    make your derived class much bigger than it would be if you did
    not use MI (but rather used a chained approach). There is a solution
    for this, but it's a little tricky, and has its own set of issues.

    > Does anybody know a good article specifically about this or else
    > would somebody care to explain it to me in this newsgroup?


    An interesting discussion to check out would be on the Boost
    developer list. You can find the archives on Google. The thread
    is about Loki::SmartPtr, which uses MI in a big and obvious way.
    Quite a few issues relating to MI came up in that discussion. Look
    for 'SmartPtr' and 'MI'.

    Dave
    David B. Held, Sep 23, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. maxw_cc
    Replies:
    1
    Views:
    3,118
    Martijn van Steenbergen
    Dec 21, 2003
  2. r.z.
    Replies:
    13
    Views:
    539
  3. Ethan Furman

    package import dangers

    Ethan Furman, Oct 6, 2009, in forum: Python
    Replies:
    7
    Views:
    252
    Dave Angel
    Oct 7, 2009
  4. Rouslan Korneychuk
    Replies:
    8
    Views:
    588
    Rouslan Korneychuk
    Feb 10, 2011
  5. Dale Martenson

    The dangers of sleeping ...

    Dale Martenson, Jun 10, 2004, in forum: Ruby
    Replies:
    2
    Views:
    104
    Michael Geary
    Jun 12, 2004
Loading...

Share This Page