模板专门化与int一起使用,并且以double作为类失败

时间:2013-06-17 14:54:41

标签: c++ templates

我有一个简单的模板:

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失败,“所需类型不匹配”。有什么想法吗?

1 个答案:

答案 0 :(得分:10)

非类型模板参数不能是浮点类型。只允许使用整数类型,枚举,指针和引用。