谁能给我解释一下为什么下面的错误会导致“非类型模板参数不是常量表达式”的错误,以及如何处理它?
#include <array>
class Test
{
public:
Test(int n) : num_requests(n/2){};
const int num_requests;
void func()
{
std::array <int,num_requests> test_array;
};
};
发布于 2021-04-21 18:13:23
使用模板“like this”参数
#include <array>
template <int n>
struct Test
{
void func()
{
std::array <int,n/2> test_array;
};
};
int main() {
auto t = Test<10>{};
t.func();
}
https://stackoverflow.com/questions/67193705
复制相似问题