Inheritance problem

  • Thread starter Morten Aune Lyrstad
  • Start date
M

Morten Aune Lyrstad

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

Ivan Vecerina

Morten Aune Lyrstad said:
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
 
M

Morten Aune Lyrstad

Ivan said:
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
 
I

Ivan Vecerina

Morten Aune Lyrstad said:
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/ThinkingInCPP2e.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 base class

Cheers,
Ivan
 

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
474,298
Messages
2,571,540
Members
48,275
Latest member
tetedenuit01

Latest Threads

Top