By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,081 Members | 861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,081 IT Pros & Developers. It's quick & easy.

Inheritance problem

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
"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

P: n/a
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

P: n/a
"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.