在带有函数参数的函数中声明静态数组时出错
int fun(int x)
{
int a[x]; //No Error
static int b[x]; //Error "storage size of x is not constant
int *f = new int[x+1]; //NO ERROR--NEW OPERATOR USED TO DEFINE THE ARRAY
}
为了声明数组“b”没有任何错误,应该在第 2 行中更改什么。
最佳答案
你的问题是你不能在没有初始化的情况下定义一个 const something 的数组,如果它是动态大小的,就没有办法初始化它!
关于c++ - 静态数组定义错误c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27731766/