constexpr的可变长度数组错误

问题描述 投票:0回答:2

我有一个带有成员函数的类,该函数声明一个数组,数组的大小基于公式。

template <int SIZE>
class{
   constexpr int lookup(const int) const
   {
      return n * n + n;
   }
   inline void func()
   {
       double array[lookup(SIZE)];
   }
};

这给我vla错误。我认为它应该起作用,因为SIZE在编译时已解决,并且查找是一个constexpr。我知道以下方法会起作用:

template <int SIZE>
class{

   inline void func()
   {
       constexpr int sz = SIZE * SIZE + SIZE;
       double array[sz];
   }
};

我想我只是想找出原因

c++ arrays c++11 constexpr
2个回答
1
投票
  • 类模板必须具有名称。

0
投票

很复杂...

© www.soinside.com 2019 - 2024. All rights reserved.