模板类成员函数的显式专门化 [英] explicit specialization of template class member function
本文介绍了模板类成员函数的显式专门化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个:
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) );
}
我的编译错误是:
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
推荐答案
不幸的是,在模板
类中的模板
方法不能仅基于 template
方法参数
Unfortunately a template
method inside a template
class cannot be specialized just based on template
argument of method.
您需要专门处理模板类
也。换句话说,对于类模板
(即< T),成员方法专门化应该是完全专业化 (例如
< size_t>
),以及成员模板
)。
You need to specialize the template class
also. In other words, the member method specialization should be a complete specialization with respect to class template
(i.e. <T,U>
) params as well as the member template
params (i.e. <size_t>
).
例如,您可能必须专门制作类似的内容( demo < a>):
For example, you may have to specialize something like this (demo):
template<> // <------ you have to specialize class also
template<>
inline void A<int, double>::BindValues<1>() // <-------- see A<T,U>
{
...
}
这篇关于模板类成员函数的显式专门化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文