模板无法编译:'double'不是模板常量参数的有效类型

Nei*_*l G 11 c++ templates

template<typename T, T Min>
class LowerBoundedType {};
template<typename T> class vectorelement {};
template<> class vectorelement<Categorical> { typedef LowerBoundedType<double, 0.0> type; };
Run Code Online (Sandbox Code Playgroud)

有错误:

 error: 'double' is not a valid type for a template constant parameter
Run Code Online (Sandbox Code Playgroud)

Jam*_*lis 12

对非类型模板参数有效的唯一数字类型是整数和枚举.因此,您不能拥有类型的非类型模板参数double.

  • 我不知道为什么这条规则是个好主意. (3认同)
  • 好吧,这将需要标准化精度并舍入wrt浮点算法,不是吗?恕我直言,这是不行的。 (2认同)