const int MAXWIDTH = 512;
const int MAXHEIGHT = 512;
void readImage(int image[][MAXHEIGHT], int &width, int &height)
....
void writeImage(int image[][MAXHEIGHT], int width, int height)
....
int main ()
{
int image[][MAXHEIGHT], width, height;
readImage (image, &width, &height);
writeImage (image, width, height);
return 0;
}
我在 main 函数中不断收到““图像”的存储大小未知”,但不确定为什么。
最佳答案
除非使用初始化列表,否则在声明数组时不能执行 int image[][MAXHEIGHT];
。即
int image[][5]={ {1,2,3,4,5},{6,7,8,9,10} };//is OK and the compiler get the row size from your initializer list and creates image[2][5]
int image[][5];//this is not OK because the compiler can't know the size of the row when creating the arrray
int image[MAXWIDTH][MAXHEIGHT];//OK because you specified both dimensions
在指定函数的形参时,可以保留二维数组的行维度,即
void somefunction(image[][MAXWIDTH])//is OK
关于c++ - 存储大小未知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36668615/