错误:必须使用括号括起的初始化程序初始化数组

时间:2014-11-25 00:40:17

标签: c++ arrays templates static

我有一段C ++代码:

template <typename WorkType, int Degree = 2> class PolynomialFunction {
 public:
  static constexpr int kNumberCoefficients[] = { 0, 3, 6, 10, 15 };
  static const int kPolyDimension = kNumberCoefficients[Degree];
  ...
 private:
  WorkType polynom_[kPolyDimension];
  ...

之前编译好但突然(可能是新的编译器)它失败并出现以下错误:

  

./ polynomial_function.h:实例化&#39; constexpr const int   PolynomialFunction :: kNumberCoefficients []&#39;:
  ./polynomial_function.h:84:56:来自&#39; const int   PolynomialFunction :: kPolyDimension&#39;
  ./polynomial_function.h:309:35:来自&class 39   PolynomialFunction&#39;
./segment.h:321:17:必填   从这里起./polynomial_function.h:83:24:错误:初始化程序   无法确定多项式函数:: kNumberCoefficients&#39;的大小。
./polynomial_function.h:83:24:错误:   必须使用括号括起初始化器初始化数组   ./polynomial_function.h:实例化&#39;类   PolynomialFunction&#39;:./segment.h:321:17:必需   从这里

顺便说一下。第83行是&#39; kNumberCoefficients&#39;的声明。第309行是多项式_&#39;的声明。任何想法为什么失败?感谢。

0 个答案:

没有答案