使用struct变量时出现C++错误

sou*_*w93 4 c++ struct

我有这个结构:

struct noduri {
    int nod[100];
};
Run Code Online (Sandbox Code Playgroud)

而这个功能:

int clearMatrix(int var)
{
    cout << all[1].nod[30];
}

int main()
{
    noduri all[100];
    cout << all[1].nod[30];
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我希望将结构分配给数组的所有100个元素all[],当我做的cout << all[1].nod[30];一切正常,没有错误,它输出0.当我打电话时,clearMatrix(1)我得到了这个错误:error: request for member nod in all[1], which is of non-class type int,我做错了什么?!

das*_*ght 6

数组变量allmain函数的本地变量,因此clearMatrix除非将指针传递给函数,否则不能引用它:

int clearMatrix(int var, noduri *all)
{
    cout<<all[1].nod[30];
}


int main()
{
    noduri all[100];
    clearMatrix(5, all);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)