Accessing an iterator after the end of a list

Hi all,
I'm trying to understand the code at the bottom of my post. I am working with a someone else's code and don't have a lot of experience in C++. My problem is that in the second loop it is accessing a field in an object pointed to by the first iterator. However, surely this iterator is now equal to the end of the array as it is the exit condition of the first loop.

Would someone be able to explain to me how this is working?

Any help would be much appreciated. Thanks.

1
2
3
4
5
6
7
8
9
for(iter=M.mappings.begin(); iter!=M.mappings.end(); iter++)	{
	another.erase(iter->target);
	s<< "\t\tdb"<<iter->target<<" [label=\""<<G2->getNodeAttrs(iter>source)->find("name")->second.value<<"\" shape=box style=filled fillcolor=lightblue color=blue];\n";		
}
		
for(p1=another.begin(); p1!=another.end(); p1++)
{
	s<< "\t\tdb"<< (*p1)<<" [label=\""<<G2->getNodeAttrs(iter->source)- >find("name")->second.value<<"\" shape=box];\n";
}
What's the point of this code? At first glance, I'd have to agree that it doesn't really make sense...
It is supposed to output a graph into DOT format. This part of the code is for outputting the vertices. I'm glad I'm not being stupid in thinking this doesn't make sense.
Hm, try putting a check (or a breakpoint) after the first for loop and check what iter is pointing at.
Topic archived. No new replies allowed.