Connecting Tech Pros Worldwide Help | Site Map

Understanding problem with multiple inheritance

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 05:49 AM
lothar.behrens@lollisoft.de
Guest
 
Posts: n/a
Default Understanding problem with multiple inheritance

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


  #2  
Old July 23rd, 2005, 05:49 AM
Me
Guest
 
Posts: n/a
Default 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.

  #3  
Old July 23rd, 2005, 05:49 AM
lothar.behrens@lollisoft.de
Guest
 
Posts: n/a
Default 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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.