There are two problems in your code. Firstly, the second specialization is illegal because
template<> // parameters useable for the specialization of A you refer to // since it is a function, no partial specialization is allowed. template<typename S> // parameters for the function parameters void A<B2<S>> // S can not be used here! ::f(S x) // only here { }
If I changed it to
template<> template<typename S> void A<B2<int>>::f(S x) { }
it works, and now the second problem opens:
second.f<B2<int>>(5);
This sets S to B2<int> , and the function expects the parameter S x - but the integer 5 cannot be converted to this type. Change it to:
B2<int> x; second.f<B2<int>>(x);
and it also works.
Please note that this may not solve the problem you are trying to solve, it just explains what is happening.
Thinking of your editing: I think that the fact that you are trying to specialize in T=std::tuple<...> already indicates the direction: T is a parameter of template A , and that is what you should specialize. Maybe something like:
template< typename T > class F // used to implement f(), so you can specialize // just F/f() instead of the whole class A { void f(T x) { } }; template< typename T1, typename T2 > class F< std::tuple< T1, T2 > > { void f(T1 x, T2 y) { } }; template< typename T > class A : public F< T > {
source share