Here's a virtual inheritance-based solution that I mentioned in the comments:
class FirstInterface
{
virtual int getId() const = 0;
};
class SecondInterface
{
virtual void setId(int id) = 0;
};
class CombinedInterface : virtual public FirstInterface,
virtual public SecondInterface
{
};
class FirstConcrete : virtual public FirstInterface
{
virtual int getId() const
{
return 1;
}
};
class CompleteConcrete : virtual public FirstConcrete,
virtual public CombinedInterface
{
virtual void setId(int id) { }
};
void example()
{
CombinedInterface * combinedInterface = new CompleteConcrete();
}
, ( ), , CompleteConcrete CombinedInterface SecondInterface. : CompleteConcreate CombinedInterface, SecondInterface.
. . ++, , TMK. , -. :
, , - .
P.S. , . , , CombinedInterface , - , :
void somefunction(CombinedInterface &object);
.
:
void somefunction(FirstInterface &first, SecondInterface &second);
, . CompleteConcrete, , - . , , - :
template<typename T> void somefunction(T &&t)
{
real_somefunction(std::forward<T>(t), std::forward<T>(t));
}
void real_somefunction(FirstInterface &first, SecondInterface &second);
CombinedInterface , somefunction(), real_somefunction() .
, , ?
class combined_pointer : public std::pair<FirstInterface *, SecondInterface *> {
public:
template<typename T> combined_pointer(T *t)
: std::pair<FirstInterface *, SecondInterface *>(t, t)
{}
};
.