模板类成员函数的显式特化
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
类中的template
方法不能仅仅基于方法的template
参数进行专门化。
您还需要专门化template class
。换句话说,对于class template
(即<T,U>
)参数以及成员template
参数(即<size_t>
),成员方法专门化应该是完全专门化。
例如,您可能需要专门化如下(demo):
template<> // <------ you have to specialize class also
template<>
inline void A<int, double>::BindValues<1>() // <-------- see A<T,U>
{
...
}
您要做的是对函数进行部分模板专门化,这是不允许的。
你可以在N
上为a的模板专门化(例如A<int, int>::BindValues<N>()
)定义模板函数,但不允许其他方式。
相关文章:
- 如何使用指针传递给函数的数组中对象的函数成员
- c++构造函数成员初始化:传递参数
- 创建 std::函数,它返回具有函数成员值的变量.分段错误
- 如何在C++通过公共函数访问私有函数成员?
- 解释了构造函数成员初始化列表
- 调用std::函数成员时内存损坏
- 是否可以为模板类的模板函数成员设置别名?
- 捕获 lambda 函数C++成员变量
- 构造函数成员初始值设定项跨成员列出,安全吗?
- 获取与在模板参数中传递的函数成员类型相同的类
- 如何从公共函数成员访问地图私有成员
- C 构造函数成员分配优化
- 使用命名空间进行函数成员定义
- 函数成员作为 CUDA 内核的参数
- 模板基类函数成员的别名
- 函数成员中用于void和继承的enable_if
- 头文件中是否定义了一个很长的Class函数成员
- 类内/构造函数成员初始化
- 使用指向部分专用函数成员的指针自动填充向量
- 指向函数成员的指针