我有一个简单的模板:
template<class T, T N>
bool VerifyGT(T value) {
return value > N;
}
bool (*test1)(int) = &VerifyGE< int, (int) 0>; // (1)
bool (*test2)(double) = &VerifyGE< double, (double) 0.0>; // (2)
编译时:test1 初始化成功,test2 失败并显示“与所需类型不匹配”。有什么想法吗?
最佳答案
非类型模板参数不能是浮点类型。仅允许整数类型、枚举、指针和引用。
关于c++ - 模板特化适用于 int 而失败于 double 作为一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17150571/