代码之家  ›  专栏  ›  技术社区  ›  Neil G

模板编译失败:“double”不是模板常量参数的有效类型

  •  11
  • Neil G  · 技术社区  · 16 年前
    template<typename T, T Min>
    class LowerBoundedType {};
    template<typename T> class vectorelement {};
    template<> class vectorelement<Categorical> { typedef LowerBoundedType<double, 0.0> type; };
    

    有错误:

     error: 'double' is not a valid type for a template constant parameter
    
    1 回复  |  直到 16 年前
        1
  •  12
  •   James McNellis    16 年前

    对于非类型模板参数,唯一有效的数字类型是整数和枚举。所以,不能有类型为的非类型模板参数 double .

        2
  •  0
  •   angelos.p    6 年前

    • 整型(例如int或long;)
    • 指向对象的指针或引用
    • 指向函数的指针或引用

    因此它不能是双重类型或类类型。 一般来说,非类型参数的基本原理是允许容器的大小和范围限制。