Reputation: 1
Im trying to process an array of structs but im recieving this error when accessing members: "must have class/struct/union"
struct person
{ int a; int b; int c;
}
person myArray[10];
int main()
{
for(var i = 0; i < 10; i++)
{
//Assume that connection string already established
outdata<< myArray[i].a << myArray[i].b << myArray[i].c << endl;//Error occurs here when accessing the members within my array of structs
}
return 0;
}
Please advise.
Upvotes: 0
Views: 1787
Reputation: 11787
1st correction:
struct person
{ int a; int b; int c;
} myArray[10];
2nd correction:
for(var i = 0; i < 10; i++)
var
is not suported in c++. Instead you can use auto
if you are running in VS2010 or above. Or else you will have to use int
Upvotes: 0
Reputation: 3174
You should do
struct person
{ int a; int b; int c;
} ;
^^^^
person myArray[10];
or
struct person
{ int a; int b; int c;
} myArray[10];
In the first case you defining a new type "person" (terminated by semocolon) and then declaring an array "myArray" of this new type "person".
In the second case you combine type declaration and variable definition which is allowed for C/C++.
Upvotes: 3
Reputation: 206508
struct person { int a; int b; int c; } ;
^^^^
You missed the ;
.
Upvotes: 9