我有一个简单的模板:
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失败,“所需类型不匹配”。有什么想法吗?
答案 0 :(得分:10)
非类型模板参数不能是浮点类型。只允许使用整数类型,枚举,指针和引用。