How to define a class MultiInherit<MyTuple<X1,X2,...>>
to inherit from X1,X2,...
?
I want to pass MyTuple<X1,X2,...>
around to compose a new object type.
template <class... Xs> class MyTuple{};
template <class MyTupleXs> class MultiInherit : public All_Xs_in_MyTupleXs { //??
};
Here is its usage and MCVE (uncompilable):-
class B{public: int b;};
class C{public: int c;};
class BC : public MultiInherit<MyTuple<B,C>> {
public: void testCompile(){
this->b=this->c;
}
};
int main(){
}
Attempt 1
Below is the closest to what I wanted.
If I get raw-types (e.g. B,C
) as template argumant rather than MyTuple<B,C>
, it would be easy :-
(MCVE, compilable)
template <class... Xs> class MultiInherit : public Xs... {
};
class B{public: int b;};
class C{public: int c;};
class BC : public MultiInherit<B,C> {
public: void testCompile(){
this->b=this->c;
}
};
Reference: Variadic templates and multiple inheritance in c++11
This doesn't solve. I want to pass an encapsulated type MyTuple<B,C>
, not the B,C
.
Attempt 2
I thought about adding a new variadic typedef MyXs
in MyTuple
:-
template <class... Xs> class MyTuple{
public: using MyXs=Xs...;
};
template <class MyTupleXs> class MultiInherit : public MyTupleXs::MyXs {
};
Nevertheless, it seems to me that the language has no such feature.
(I am new to variadic template.)