Archived
This forum has been archived. Please start a new discussion on GitHub.
Implementing multiple interfaces in a single C++ class
Hi all,
I was wondering if it was possible to implement more than one interface in as single C++ class, for example using multiple inheritance:
I cannot get this to work, gcc complains that there is "no unique final overrider" for a number of items, such as ice_id(), ice_clone(), and ice_ping().
Is there no way in which this can be made to work? What are the best alternatives here? Right now I'm thinking of making an aggregate class like this:
Is that the way to go, or are there better alternatives?
Best regards Sidney
I was wondering if it was possible to implement more than one interface in as single C++ class, for example using multiple inheritance:
class ABReceiverI: public virtual AReceiver, public virtual BReceiver { virtual void receiveA(A itemA); virtual void receiveB(B itemB); };
I cannot get this to work, gcc complains that there is "no unique final overrider" for a number of items, such as ice_id(), ice_clone(), and ice_ping().
Is there no way in which this can be made to work? What are the best alternatives here? Right now I'm thinking of making an aggregate class like this:
class ABReceiver { class AReceiverI { }; class BReceiverI { }; };
Is that the way to go, or are there better alternatives?
Best regards Sidney
0
Comments
-
As you found out, you cannot implement two interfaces with one single C++ class directly. However, you could simply define a new Slice interface derived from the two other Slice interfaces, and then implement this new Slice interface with a single C++ class.0
-
That's pretty clever ... and it works like a charm!
Thanks!0