函数原型中的参数名称

0 c c++ dev-c++

AS在函数decleration中,需要三件事,即返回值类型.功能名称.(参数类型).但参数名称不是必需的.那么为什么这个程序生成错误,当我arr[][maxCols]从函数prototype(void readMatrix(int arr[][maxCols] );)中删除参数name ()

简单来说.

void readMatrix(int arr[][maxCols] );    // fine and no error.

void readMatrix(int);                    // but this generates error when argument name is not mentioned in function prototype.
Run Code Online (Sandbox Code Playgroud)

Chr*_*ckl 7

因为[][maxCols]不属于名称而是属于类型.

对于没有名称的声明,请写:

void f(int [][maxCols])
Run Code Online (Sandbox Code Playgroud)

而原始数组通常是一个糟糕的选择.使用std::vectorstd::array.