I have this struct:
struct noduri {
    int nod[100];
};
and this function:
int clearMatrix(int var)
{
    cout << all[1].nod[30];
}
int main()
{
    noduri all[100];
    cout << all[1].nod[30];
    return 0;
}
and I want the struct to be assigned to all 100 elements of array all[], when I do cout << all[1].nod[30]; everything works fine, no errors, it outputs 0. When I call clearMatrix(1) I get this error : error: request for member nod in all[1], which is of non-class type int, what am I doing wrong ?!
The array variable all is local to the main function, so you cannot reference it in clearMatrix unless you pass a pointer to it into the function:
int clearMatrix(int var, noduri *all)
{
    cout<<all[1].nod[30];
}
int main()
{
    noduri all[100];
    clearMatrix(5, all);
    return 0;
}
                        you are reffering in the function that array which is not in its scope, you need to do it as
int clearMatrix(int var,noduri *all)
 {
   cout<<all[1].nod[30]; // as here you have the base address of the array of type noduri you can refer it.
 }
 int main()
 {
noduri all[100];
clearMatrix(5, all);
return 0;
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With