"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