removing elements from a list with an iterator, then placing it into another list.

Started by
1 comment, last by EGD Eric 20 years ago
In the enginuity articles, Richard removes dead objects from the liveObjects list and adds them to the deadObjects list like this: liveObjects.remove(this); deadObjects.push_back(this); But he says that remove is inneficient, because it searches the whole list for the object before removing it. He says that using an iterator would be more efficient. Which function uses an iterator to remove items? The only one I've found is erase . And that one deallocates memory for the pointer as well. That won't do, because I need to remove the item from one list and put it into another list. [edited by - EGD Eric on April 15, 2004 1:20:18 PM]
Advertisement
erase does not deallocate memory from your pointers if its a list of pointer.(imagine how useless it would be if you had a list of nullpointers, or a list of invalid pointers)

Maybe the documentation meant that it deallocated memory for the node being erased.
Shields up! Rrrrred alert!
yes, erase() does not perform delete on the contents, just junks the node. If you thought that it did, i''ll bet you''ve got some real dandy memory leaks in there somewhere :-)

This topic is closed to new replies.

Advertisement