468,458 Members | 1,855 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,458 developers. It's quick & easy.

Inheritance problem

Hi again!

I'm having problems with inheritance. I have a base interface class
called IObject. Next I have two other interfaces classes, IControl and
ICommandMaster, which derives from IObject.

My problem is that I have a /third/ class, CCommand, which derives from
both IControl and ICommandmaster...

The error message says (Weird.....)
ambiguous access of 'Release' in 'Win32::Controls::CCommand'
could be the 'Release' in base 'CS::IObject::Release'
or the 'Release' in base 'CS::IObject::Release'

Is there a way to solve this ambiguety, or am I lost?

The ICommandMaster is an interface which is used in menus, command
buttons, toolbars and any other that might send a command.
Jul 22 '05 #1
3 2207
"Morten Aune Lyrstad" <mo****@wantsno.spam> wrote in message
news:0X******************@news4.e.nsc.no...
I'm having problems with inheritance. I have a base interface class called
IObject. Next I have two other interfaces classes, IControl and
ICommandMaster, which derives from IObject.

My problem is that I have a /third/ class, CCommand, which derives from
both IControl and ICommandmaster...

The error message says (Weird.....)
ambiguous access of 'Release' in 'Win32::Controls::CCommand'
could be the 'Release' in base 'CS::IObject::Release'
or the 'Release' in base 'CS::IObject::Release'

Is there a way to solve this ambiguety, or am I lost?


This is the typical caveat with multiple inheritance, described
in every OOP/C++ book.
So typical that this suspiciously looks like homework...

CControl contains to independent instances of the base class IObject,
and this can create all kinds of problems.

Anyway, three common solutions are:
- derive both IControl and ICommandmaster from IObject using
virtual inheritance:
class IControl : public virtual IObject { ..... };
class ICommandmaster: public virtual IObject { ..... };
- Eliminate the use of multiple inheritance...
- override the Release method (and maybe the equivalent Acquire?)
in the common subclass, and make it call the method of
a specific base class:
class CCommand { ......
virtual void Release() { IControl::Release(); }
};

Good luck,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com
Jul 22 '05 #2
Ivan Vecerina wrote:
"Morten Aune Lyrstad" <mo****@wantsno.spam> wrote in message
news:0X******************@news4.e.nsc.no...
I'm having problems with inheritance. I have a base interface class called
IObject. Next I have two other interfaces classes, IControl and
ICommandMaster, which derives from IObject.

My problem is that I have a /third/ class, CCommand, which derives from
both IControl and ICommandmaster...

The error message says (Weird.....)
ambiguous access of 'Release' in 'Win32::Controls::CCommand'
could be the 'Release' in base 'CS::IObject::Release'
or the 'Release' in base 'CS::IObject::Release'

Is there a way to solve this ambiguety, or am I lost?

This is the typical caveat with multiple inheritance, described
in every OOP/C++ book.
So typical that this suspiciously looks like homework...

CControl contains to independent instances of the base class IObject,
and this can create all kinds of problems.

Anyway, three common solutions are:
- derive both IControl and ICommandmaster from IObject using
virtual inheritance:
class IControl : public virtual IObject { ..... };
class ICommandmaster: public virtual IObject { ..... };
- Eliminate the use of multiple inheritance...
- override the Release method (and maybe the equivalent Acquire?)
in the common subclass, and make it call the method of
a specific base class:
class CCommand { ......
virtual void Release() { IControl::Release(); }
};

Good luck,
Ivan


Thanks for your quick reply. No, actually, it is not a homework problem.
I am writing a win32 ui library. The reason I don't know about this is
that I am 100 % self taught, no books no nuthin'. So there's a billion
and one things I don't know. For example:

Virtual inheritance is something new to me. Could you please fill me in
on the basics?

Yours,
Morten Aune Lyrstad
Jul 22 '05 #3
"Morten Aune Lyrstad" <mo****@wantsno.spam> wrote in message
news:Uc******************@news4.e.nsc.no...
Thanks for your quick reply. No, actually, it is not a homework problem. I
am writing a win32 ui library. The reason I don't know about this is that
I am 100 % self taught, no books no nuthin'. So there's a billion and one
things I don't know. For example:

Virtual inheritance is something new to me. Could you please fill me in on
the basics?


Hi Morten,
You could try a book such as Thinking in C++ -- a free pdf version of it is
available online: http://www.mindview.net/Books/TICPP/...ngInCPP2e.html
I would suggest reading vol 2 chapter 6.

You also find more texts on this topic using:
http://www.google.com/search?q=virtual%20base%20class

Cheers,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Steve Jorgensen | last post: by
22 posts views Thread by Matthew Louden | last post: by
8 posts views Thread by Gaetan | last post: by
5 posts views Thread by colint | last post: by
5 posts views Thread by a | last post: by
3 posts views Thread by Leo Seccia | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.