成员函数的部分模板专用化:"prototype does not match"
Partial template specialization of member function: "prototype does not match"
我正在尝试部分专业化一个未模拟类的模板成员功能:
#include <iostream>
template<class T>
class Foo {};
struct Bar {
template<class T>
int fct(T);
};
template<class FloatT>
int Bar::fct(Foo<FloatT>) {}
int main() {
Bar bar;
Foo<float> arg;
std::cout << bar.fct(arg);
}
我会收到以下错误:
c.cc:14: error: prototype for ‘int Bar::fct(Foo<FloatT>)’ does not match any in class ‘Bar’
c.cc:9: error: candidate is: template<class T> int Bar::fct(T)
如何修复编译器错误?
不允许对功能的部分专业化(成员或其他方式)。
使用超载:
struct Bar {
template<class T>
int fct(T data);
template<class T> //this is overload, not [partial] specialization
int fct(Foo<T> data);
};
相关文章:
- 将系数存储在头文件的数组中("does not name a type"错误)
- 当初始值设定项是基类名时'initializer does not name a non-static data member or base class'错误
- 由于"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int",我现在无法编
- 如何解决"'mutex' in namespace 'std' does not name a type"?
- 在 C++ 中使用命名空间时出现"does not name a type"错误
- 已声明时"Does not name a type"错误
- 嵌套类"does not name a type"
- "what does ":*** [可执行文件] 错误 1 " mean ?"
- 这在C++ "It does not own the underlying data, and so is cheap to copy or assign"中意味着什么
- Eigen loadMarket does not compile
- 有没有类似的函数,比如 c++ 中的 JS Array.prototype.map?
- 为什么当我的代码超出函数范围时,"does not name a type"出现编译器错误?
- 创建C++ Redis 模块 - "does not export RedisModule_OnLoad() symbol"
- 无法分隔标头类。我得到"does not name a type"
- 模板元编程:"does not have integral or enumeration type"
- 如何修复类函数"prototype does not match"和"cadidate is"错误
- #define 的"Declaration does not declare anything"错误
- 分成 .h 和 .cpp 文件时"prototype does not match any class"错误
- 如何在配置中禁用"compiler does not halt on function prototype mismatch"错误?
- 成员函数的部分模板专用化:"prototype does not match"