Explicit specialization of member function of a template class

I have it:

template<class T, class U> class A { template<size_t N> void BindValues(); } template<class T, class U> template<size_t N> inline void A<T, U>::BindValues() { conn->setValue<N-1>( std::get<N-1>(m_Tuple) ); BindValues<N-1>(conn); } template<class T, class U> template<> inline void A<T, U>::BindValues<1>() { conn->setValue<0>( std::get<0>(m_Tuple) ); } 

My compilation error:

 invalid explicit specialization before '>' token enclosing class templates are not explicitly specialized template-id BindValues<1> for void A<T, U>::BindValues() does not match any template declaration 
+7
source share
2 answers

Unfortunately, the template method inside the template class cannot be specialized solely on the basis of the template argument of the method.

You need to specialize the template class as well . In other words, the specialization of the member method should be a full specialization in the parameters of class template (i.e., <T,U> ), as well as the parameters of the template member (i.e., <size_t> ).

For example, you may need to specialize in this ( demo ):

 template<> // <------ you have to specialize class also template<> inline void A<int, double>::BindValues<1>() // <-------- see A<T,U> { ... } 
+6
source

What you are trying to do is partial template specialization for a function that is not valid.

You can define a template function on N to specialize template A (for example, A<int, int>::BindValues<N>() ), but vice versa.

+3
source

All Articles