How can i loop thru a stl::List and store the value of one of the objects for use later in the function?
Particle *closestParticle;
for(list::ite
For a list
, the only way to invalidate an iterator is to erase
it. So I suspect you're calling list.erase(p1)
at some point in the loop. You need to make a copy of the iterator, move p1
back one, and then erase the copy.
EDIT: Oh wait, did you mean it doesn't compile? If so, see @sbi's answer. But you really need to word your question in a good way. What is your compile error? Or does it fail at run-time? In this case, however, I believe you mean a compile error.