473,385 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Inheritance ambiguety problem

Hi there! I have written this message before, but for some reason it did
not appear to show up on the board. If it does, then I have a problem
with my newsgroup app, and I apologize for double posting.

Here's my problem:
I have a base interface class, named IObject. Next I have two classes
based on this, named IControl and ICommandMaster. Third I have a control
class named CCommand which inherits from /both/ IControl and
ICommandMaster. So, obviously, my compiler screams
<quote>
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'
</quote>.

(Weird error message, btw;-)). But can I somehow solve this ambiguety?
Both IControl and ICommandMaster _must_ derive from IObject somehow,
because I have to be able to call a function named Release in IObject. I
might have a ICommandMaster which is _not_ a IControl and vice versa.
Jul 22 '05 #1
7 1453

"Morten Aune Lyrstad" <mo****@wantsno.spam> wrote in message
news:g4******************@news4.e.nsc.no...
Hi there! I have written this message before, but for some reason it did
not appear to show up on the board. If it does, then I have a problem with
my newsgroup app, and I apologize for double posting.

Here's my problem:
I have a base interface class, named IObject. Next I have two classes
based on this, named IControl and ICommandMaster. Third I have a control
class named CCommand which inherits from /both/ IControl and
ICommandMaster. So, obviously, my compiler screams
<quote>
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'
</quote>.

(Weird error message, btw;-)). But can I somehow solve this ambiguety?
Both IControl and ICommandMaster _must_ derive from IObject somehow,
because I have to be able to call a function named Release in IObject. I
might have a ICommandMaster which is _not_ a IControl and vice versa.


In that case, you can use "virtual" inheritance (as opposed to public,
etc.). A good C++ book should show you how to set that up properly.

-Howard
Jul 22 '05 #2
On Mon, 03 Jan 2005 22:47:58 +0100, Morten Aune Lyrstad wrote:

<snip>
(Weird error message, btw;-)). But can I somehow solve this ambiguety?
Both IControl and ICommandMaster _must_ derive from IObject somehow,
because I have to be able to call a function named Release in IObject. I
might have a ICommandMaster which is _not_ a IControl and vice versa.


A critical question: what is supposed to happen when the Release function
is called on CCommand? Does it call Release on both parent classes?

Virtual inheritance will solve multiple reference counts (assuming that's
what's going on :) by sharing the common data, but you still need to
implement Release in CCommand to invoke the correct functionality.

BTW, though this is a bit off-topic, the usual way this is solved in COM
is to use aggregation, not inheritance, using QueryInterface to pick the
right interface object.

- Jay

Jul 22 '05 #3
Jay Nabonne wrote:
On Mon, 03 Jan 2005 22:47:58 +0100, Morten Aune Lyrstad wrote:

<snip>
(Weird error message, btw;-)). But can I somehow solve this ambiguety?
Both IControl and ICommandMaster _must_ derive from IObject somehow,
because I have to be able to call a function named Release in IObject. I
might have a ICommandMaster which is _not_ a IControl and vice versa.

A critical question: what is supposed to happen when the Release function
is called on CCommand? Does it call Release on both parent classes?

Virtual inheritance will solve multiple reference counts (assuming that's
what's going on :) by sharing the common data, but you still need to
implement Release in CCommand to invoke the correct functionality.

BTW, though this is a bit off-topic, the usual way this is solved in COM
is to use aggregation, not inheritance, using QueryInterface to pick the
right interface object.

- Jay


IObject is a reference counting system. It contains the functions AddRef
and Release. When the reference count reaches zero, Release calls
'delete this'.

Why would I have to implement Release in CCommand? It is not implemented
any other place than in IObject.
Jul 22 '05 #4

"Morten Aune Lyrstad" <mo****@wantsno.spam> wrote in message
news:vy******************@news4.e.nsc.no...
Jay Nabonne wrote:
On Mon, 03 Jan 2005 22:47:58 +0100, Morten Aune Lyrstad wrote:

<snip>
(Weird error message, btw;-)). But can I somehow solve this ambiguety?
Both IControl and ICommandMaster _must_ derive from IObject somehow,
because I have to be able to call a function named Release in IObject. I
might have a ICommandMaster which is _not_ a IControl and vice versa.

A critical question: what is supposed to happen when the Release function
is called on CCommand? Does it call Release on both parent classes?

Virtual inheritance will solve multiple reference counts (assuming that's
what's going on :) by sharing the common data, but you still need to
implement Release in CCommand to invoke the correct functionality.
Not unless both IControl and ICommandMaster override the Release() function
defined in the virtual base class.
BTW, though this is a bit off-topic, the usual way this is solved in COM
is to use aggregation, not inheritance, using QueryInterface to pick the
right interface object. NB: with all due respect, the design of Microsoft COM has merits,
but it is definitely not a good example of (pure) C++ design.
- Jay


IObject is a reference counting system. It contains the functions AddRef
and Release. When the reference count reaches zero, Release calls 'delete
this'.

Why would I have to implement Release in CCommand? It is not implemented
any other place than in IObject.


People tend to name classes with an "I" prefix when the class is a purely
abstract interface - that is, when it contains only virtual abstract methods
(as: virtual void f()=0; ) and no data members.

This is the case in Microsoft COM, a previously popular component
infrastructure (now deprecated in favor of .NET/CLI).
Cheers,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Jul 22 '05 #5
>
People tend to name classes with an "I" prefix when the class is a purely
abstract interface - that is, when it contains only virtual abstract methods
(as: virtual void f()=0; ) and no data members.

This is the case in Microsoft COM, a previously popular component
infrastructure (now deprecated in favor of .NET/CLI).
Cheers,
Ivan


I respect that, but I use the I to identify classes which _must_ be
derived from and cannot be used alone.
Jul 22 '05 #6
"Morten Aune Lyrstad" <mo****@wantsno.spam> wrote in message
news:xy******************@news2.e.nsc.no...
People tend to name classes with an "I" prefix when the class is a purely
abstract interface - that is, when it contains only virtual abstract
methods
(as: virtual void f()=0; ) and no data members. NB: I should have said "Some people..." (doesn't even include me...)
This is the case in Microsoft COM, a previously popular component
infrastructure (now deprecated in favor of .NET/CLI).
Cheers,
Ivan


I respect that, but I use the I to identify classes which _must_ be
derived from and cannot be used alone.


And that is perfectly fine: I just wanted to explain
Jay's misinterpretation. My intent was not to defend it ;)

Some use A (like Abstract) as a prefix for classes that
are not pure interfaces but have to be derived from.
Many others prefer not to use any such prefix.

:)

Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Jul 22 '05 #7
I never got an answer on this question, so I'll rephrase it: Do I have
to reimplement Release if it is created like this in IObject?

virtual bool Release() {
if (objectReferenceCount <= 1) {
MemDelete this;
return true;
} else {
objectReferenceCount--;
return false;
}
}

objectReferenceCount gets the value 1 in the constructor.
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
3
by: Morten Aune Lyrstad | last post by:
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. ...
5
by: ma740988 | last post by:
Prefer composition to inheritance (can't recall which text I stole that line from) is one of the fundamental tenets thats engrained in my mind. Having said that inheritance requires careful...
14
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
6
by: VR | last post by:
Hi, I read about Master Pages in ASP.Net 2.0 and after implementing some WinForms Visual Inheritance I tryed it with WebForms (let's say .aspx pages, my MasterPage does not have a form tag itself...
5
by: colint | last post by:
Hi I'm fairly new to c++ and I have a question regarding inheritance. I'm trying to create a class based on 2 inherited classes, e.g. class A { ... } class B: public A
5
by: a | last post by:
Hi, I have an oop inheritance graph problem. What is the difference betweent the following 2 inheritance graph? How does the C++ solve the naming conflict problem for multiple inheritance...
3
by: Leo Seccia | last post by:
Hello everyone, I have a c# project with a sql server database. I have a number of lookup tables in my database which I successfully managed to import into my LINQ dataclasses. eg. Table:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.