Home Help Center

Implementing multiple interfaces in a single C++ class

sidneysidney Member Sidney CadotOrganization: TNO, NetherlandsProject: sonar processing software
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:
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

Comments

  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    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.
  • sidneysidney Member Sidney CadotOrganization: TNO, NetherlandsProject: sonar processing software
    That's pretty clever ... and it works like a charm!

    Thanks!
Sign In or Register to comment.