Re: Iterator Question?

[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]

Posted by Thrasher on April 22, 2001 at 17:27:07:

In Reply to: Iterator Question? posted by David Shell on April 22, 2001 at 17:24:03:

When you delete the element that the iterator was pointing to and then try to say iterator++ it doesn't know where to increment from. Try making a little piece of code to keep track of the element right before the one that you delete and then increment should work for you.

By the way, make sure you take into account the possibility that you're deleting from the beginning of the list.

There may be a better way of doing this, but this is how I worked it out.

: I am getting an Access Violation...
: My Ecosystem is looping through the lists and telling all the Creatures in the lists to tick, and one of them dies, and then then next time around the loop, it crashes. It is deleting the creature just fine, and supposedly removing it from the list, but the next time around, it hits a creature that is already Dead, and this makes it crash. I am not sure if this is a problem with my iterator or not. The notes say that inserting/deleting from an stl list does not invalidate the iterators, so I was just continuing on by incrementing the iterator, and going back to the top of the loop again. Is this wrong? Anyone have any suggestions?

Follow Ups:

Post a Followup




Optional Link URL:
Link Title:
Optional Image URL:

[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]