I created some test code to debug one of my problems, and I think I narrowed it down. One list has shared pointers, the other has addresses of the object pointed to by the shared pointer. When the shared pointer is deleted, it doesn't set the object to NULL so the list full of addresses has some bogus value. Here's some code to explain:
Code:
list<shared_ptr<Enemy>> elist;
list<shared_ptr<Enemy>>::iterator it;
Enemy* ep;
{
shared_ptr<Enemy> e(new Enemy);
elist.push_back(e);
ep=e.get();
}
it=elist.begin();
//THIS DOES NOT WORK, but indicates what I want: (*it)=NULL;
elist.erase(elist.begin());
//this fails
assert(ep);
How can I assign a new value to what an iterator is pointing to, or otherwise fix this?