Hi,
I'm having troubles using iterator and const_iterator.
Let's consider this code :
|
Source code
|
1
2
3
4
5
|
LabeledGraph::node_children_t::iterator it;
for (it=g->children().begin(); it!=g->children().end(); ++it) {
// do someting with (*it)
}
|
this code crashes when it is of type iterator, but works well when it is of type const_iterator. I don't understand why
More surprisingly, writing
|
Source code
|
1
|
printf("%s\n", (*(g->children().begin()))->toString().c_str());
|
works well, while writing :
|
Source code
|
1
2
3
|
LabeledGraph::node_children_t::iterator it = g->children().begin();
printf("%s\n", (*it)->toString().c_str());
|
crashes. It seems that dereferencing it causes crashes when it is of type iterator.
Any explanations ?
My problem is related to that specific code. I always use iterators and everything goes well. Perhaps it is the fact that the code runs in a thread ?
Thanks