为什么这是部分专业化?(我能做什么?
Why is this partial specialization? (And what can I do?)
我有几个模板类的成员函数,它们本身就是模板。对于所有这些,编译器都抱怨:error: function template partial specialization is not allowed
.
但我不明白为什么这应该是部分专业化。我该怎么做才能实现我在下面代码中编写的内容?
template <int DIM>
class A : public B
{
public:
template <class T>
T getValue(void* ptr, int posIdx);
template <class T>
T getValue(void* ptr, int posIdx, int valIdx);
template <class T>
T getValue(void* ptr, Coords& coord, Coords& size, int valIdx);
template <class T>
void setValue(void* ptr, int posIdx, T val);
template <class T>
void setValue(void* ptr, int posIdx, int valIdx, T val);
template <class T>
void setValue(void* ptr, Coords& coord, Coords& size, int valIdx, T val);
};
// example how the functions are implemented:
template <int DIM>
template <class T>
T A<DIM>::getValue<T>(void* ptr, Coords& coord, Coords& size, int valIdx){
T val = static_cast<T>(some_value); // actually, its more complicated
return val;
}
你的问题是,正如你的编译器所说,你正在尝试部分专用化一个函数模板:
template <int DIM>
template <class T>
T A<DIM>::getValue<T>(void* ptr, Coords& coord, Coords& size, int valIdx){
// here^^^
T val = static_cast<T>(some_value); // actually, its more complicated
return val;
}
这里不需要专门化函数,只需正常定义即可:
template <int DIM>
template <class T>
T A<DIM>::getValue(void* ptr, Coords& coord, Coords& size, int valIdx){
// no more <T>^
T val = static_cast<T>(some_value); // actually, its more complicated
return val;
}
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 警告处理为错误这里有什么问题
- 什么时候调用组成单元对象的析构函数
- #定义c-预处理器常量..我做错了什么
- 如何使用默认参数等选择模板专业化
- 努力将整数转换为链表。不知道我在这里做错了什么
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 什么时候在C++中返回常量引用是个好主意
- 当在同一名称空间中有两个具有相同签名的函数时,会发生什么
- C++避免重复声明的语法是什么
- c++库的公共头文件中应该包含什么
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 有什么方法可以遍历结构吗
- 函数模板部分专业化-有什么解决方法吗
- 遍历模板参数包,没有争论的专业化的作用是什么?
- 不允许功能模板的部分专业化背后的理由是什么?
- 对于类型是类模板专业化的参数,ADL背后的理由是什么
- c++中两种形式的专业化模板实现之间的区别是什么
- 为什么这是部分专业化?(我能做什么?
- 专业化和重载有什么区别