Connecting Tech Pros Worldwide Help | Site Map

Understanding problem with multiple inheritance

lothar.behrens@lollisoft.de
Guest
 
Posts: n/a
#1: Jul 23 '05
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

Me
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Understanding problem with multiple inheritance


> I have a base class and virtually derived from them in two other[color=blue]
> 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));
> }[/color]

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.

lothar.behrens@lollisoft.de
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Understanding problem with multiple inheritance


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

Closed Thread