Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Understanding problem with multiple inheritance

Reply
Thread Tools

Understanding problem with multiple inheritance

 
 
lothar.behrens@lollisoft.de
Guest
Posts: n/a
 
      07-02-2005
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

 
Reply With Quote
 
 
 
 
Me
Guest
Posts: n/a
 
      07-03-2005
> 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.

 
Reply With Quote
 
 
 
 
lothar.behrens@lollisoft.de
Guest
Posts: n/a
 
      07-03-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
inheritance, multiple inheritance and the weaklist and instance dictionaries Rouslan Korneychuk Python 8 02-10-2011 04:02 AM
I need help understanding inheritance and virtual functions dwightarmyofchampions@hotmail.com C++ 9 05-11-2009 03:42 PM
Problem of understanding inheritance matilda matilda Python 0 12-06-2006 11:43 PM
trouble understanding inheritance... KraftDiner Python 11 08-27-2006 07:53 PM
question and understanding about multiple inheritance Tony Johansson C++ 5 08-17-2005 12:05 PM



Advertisments