I have two structs defined as in the following:
struct vertex
{
double x;
double y;
double z;
};
struct finalVertex
{
int n;
vertex v;
};
I use the following code to iterate through the list and print all the members:
vector<finalVertex> finalVertices;
vector<finalVertex>::iterator ve;
for ( ve = finalVertices.begin(); ve < finalVertices.end(); ve++ )
{
out << *(ve).v.x << *(ve).v.y << *(ve).v.z << endl;
}
I receive the following code of error:
main.cpp:651: error: ‘class __gnu_cxx::__normal_iterator > >’ has no
member named ‘v’
What is the syntactically correct way of accessing the elements of the set?
The problem is operator precedence: write
(*ve).v.xor simpler,ve->v.x.Apart from that, I would advise you to override
operator <<for yourvertexstructure to make your code vastly more readable:and then use it like this: