Understanding problem with multiple inheritance

Discussion in 'C++' started by lothar.behrens@lollisoft.de, Jul 2, 2005.

  1. Guest

    Hi,

    I have a base class and virtually derived from them in two other
    classes.

    In turn I defined a class that derives from the two other class.


    Window < MasterWindow <
    < DetailWindow < \
    MasterDetailWindow (MI_Derived)

    In another class - a control, I cannot any more cast to the derived
    class.

    void LB_STDCALL lbOwnerDrawControl::init(lb_I_Window* parent) {
    lbDatabaseDialog* p = (lbDatabaseDialog*) parent;
    Create(p, -1, wxPoint(), wxSize(40,40));
    }

    The help from my compiler describes the error:

    'Since the relative position of a virtual base can change through
    repeated derivations, this conversion is very dangerous. All C++
    translators must report an error for this type of conversion.'

    I thought, I extend my base class (database dialog) with a master
    detail
    functionality trough MI interfaces. But it seems the wrong way.

    How can I extend a base class, that may also be a 'master form' or a
    'detail form' or even both ?

    Takes it sense or should I simply derive a MasterDetailDialog from
    DatabaseDialog, because it may be both (master -> detail -> subdetail).

    Hope this is not the wrong place for this question.

    There may be a pattern for it.

    Lothar
     
    , Jul 2, 2005
    #1
    1. Advertising

  2. Me Guest

    > I have a base class and virtually derived from them in two other
    > classes.
    >
    > In turn I defined a class that derives from the two other class.
    >
    >
    > Window < MasterWindow <
    > < DetailWindow < \
    > MasterDetailWindow (MI_Derived)
    >
    > In another class - a control, I cannot any more cast to the derived
    > class.
    >
    > void LB_STDCALL lbOwnerDrawControl::init(lb_I_Window* parent) {
    > lbDatabaseDialog* p = (lbDatabaseDialog*) parent;
    > Create(p, -1, wxPoint(), wxSize(40,40));
    > }


    Long answer: You can't static_cast from a base class to a derived class
    if the base is virtually inherited. The standard basically treats a C
    style cast as choosing between static_cast and reinterpret_cast
    (ignoring const_cast) based on a few rules. Lucky for you that the
    standard has wording so the above code would error because otherwise it
    would choose reinterpret_cast which would be bad news.

    Short answer: use dynamic_cast instead.
     
    Me, Jul 3, 2005
    #2
    1. Advertising

  3. Guest

    Thanks,

    this needs RTTI and I do not know how this interfers my wxWidgets based
    code.

    Other issue would be the fact, that I get trouble with my component
    oriented development.
    But that hasn't to do anything with pure C++ questions.

    It may be a COM/CORBA issue and how they handle interface definitions
    using MI.
    (If this is really possible)

    Lothar
     
    , Jul 3, 2005
    #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. KraftDiner

    trouble understanding inheritance...

    KraftDiner, Aug 16, 2006, in forum: Python
    Replies:
    11
    Views:
    516
    Bruno Desthuilliers
    Aug 27, 2006
  2. matilda matilda

    Problem of understanding inheritance

    matilda matilda, Dec 6, 2006, in forum: Python
    Replies:
    0
    Views:
    238
    matilda matilda
    Dec 6, 2006
  3. Tony Johansson
    Replies:
    5
    Views:
    312
    Greger
    Aug 17, 2005
  4. Replies:
    9
    Views:
    459
    Bart van Ingen Schenau
    May 11, 2009
  5. Rouslan Korneychuk
    Replies:
    8
    Views:
    604
    Rouslan Korneychuk
    Feb 10, 2011
Loading...

Share This Page