Suppose I have a large class hierarchy as a single rooted tree, with root being class A
such that each of its offsprings has its own implementation of void f(...)
and void g(...)
, with different argument lists.
I have another class class X: public A
that only uses the base class f(...)
and g(...)
in some of its methods. Now I want to extend methods in X
to all subtype of A
: say the subtype of A
be B
, the new class is class BX
. The requirement is:
- (implementation)
class BX
should usef(...)
andg(...)
fromclass B
, and all methods fromclass X
. - (interface)
class BX
should adhere to the interface ofclass A
.
The solution I came up with is to have template<typename B> class BX: public B
to avoid the diamond problem in 1.
Is there a better way to achieve what I want?