hi,
i want to use a stl list of pointers in my program, so i made a little test application to find out exactly how much "maintenance" i need to perform on them (after removing them from the list). however, the behavior of the program has got me a little confused. the code below gives no errors (as i thought it would):
it seems to me that the last a->blah() call should throw an access violation, yet it works fine (i even checked, and the destructor is being called like it should be on the delete a; line). can anyone tell me what's going on here? and what clean up i will need to worry about when handling a list of pointers? thanks!Code:#include <list> #include <iostream> using namespace std; class dummy { public: dummy() {}; ~dummy() { cout << "destructor" << endl; } void blah() { cout << "blah" << endl; } }; int main() { list<dummy*> theList; list<dummy*>::iterator it; dummy *a = new dummy(); dummy *b = new dummy(); theList.push_back(a); theList.push_back(b); cout << theList.size() << endl; for (it = theList.begin(); it != theList.end(); it++) { (*it)->blah(); } theList.remove(a); delete a; a = NULL; a->blah(); return 0; }