存储大小未知

Storage size isn't known

本文关键字:未知 存储      更新时间:2023-10-16
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;
}

我一直在主函数中得到"'图像'的存储大小未知",不知道为什么。

除非

使用初始值设定项列表,否则在声明数组时无法执行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