I have two struct
s 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.x
or simpler, ve->v.x
.
Apart from that, I would advise you to override operator <<
for your vertex
structure to make your code vastly more readable:
std::ostream& operator <<(std::ostream& out, vertex const& value) {
return out << value.x << " " << value.y << " " << value.z;
}
and then use it like this:
for ( ve = finalVertices.begin(); ve != finalVertices.end(); ve++ )
out << ve->v << endl;
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