Archived
This forum has been archived. Please start a new discussion on GitHub.
C++ : implementation of derived (extended) interfaces
Hi all,
We have a question regarding the proper way of implementing, in C++, the following interface:
What we want to do is give an implementation for Base::sayHi() that is inherited in all derived classes from Base. What we do to achieve this is use multiple inheritance:
In the Ice user manual, we couldn't find any explicit guidelines on implementing extended interfaces in the C++ language mapping section. Given the fact that we cannot use multiple inheritance in c++ to implement multiple interfaces in a single class, we were wondering if the solution given here is, in fact, the proper way.
Any comments would be appreciated.
Best regards, Sidney
We have a question regarding the proper way of implementing, in C++, the following interface:
module example { interface Base { void sayHi(); }; interface Derived extends Base { void sayHello(); }; };
What we want to do is give an implementation for Base::sayHi() that is inherited in all derived classes from Base. What we do to achieve this is use multiple inheritance:
class BaseI : public virtual public virtual example::Base { virtual void sayHi(const Ice::Current &) {} } class DerivedI: public virtual example:Derived, public virtual BaseI { virtual void sayHello(const Ice::Current &) {} }
In the Ice user manual, we couldn't find any explicit guidelines on implementing extended interfaces in the C++ language mapping section. Given the fact that we cannot use multiple inheritance in c++ to implement multiple interfaces in a single class, we were wondering if the solution given here is, in fact, the proper way.
Any comments would be appreciated.
Best regards, Sidney
0
Comments
-
Hi Sidney,
Your example is the correct approach. The C++ classes generated from Slice interfaces always use virtual inheritance, so you can reuse the implementation of a base class in a derived class like you have shown.
Note that Slice classes have different default semantics. A Slice class does not inherit virtually from Ice::Object by default; you would need to use the cpp:virtual metadata tag to enable the use of virtual inheritance.
Regards,
Mark0 -
Ok, it's good to know we're on the right track here.
Cheers, Sidney0