Understanding problem with multiple inheritance

L

lothar.behrens

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
 
M

Me

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.
 
L

lothar.behrens

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
 

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

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top