Re: [Dev-C++] Problem deleting iterator contents while iterating...
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Vale G. <val...@at...> - 2003-09-30 17:47:52
|
Edric - > On a successful match in criteria, I wish to delete the iterator and its contents away from the memory. The nice thing about STLs is that they take care of all of the fiddly bits for you. I'm not sure that an STL container implementation is required to free up the memory used by a deleted member. Don't worry about it. > However, when I attempted to call delete on the node that I want to remove, the compilation throws an error. > delete(*xIter); // Compilation fails at this point I don't think that you can dereference an iterator. Eliminate the line that won't compile. It's not needed. The member is erased by the line: resultTable.erase(xIter++); but Danger! Danger! If the container is a vector, string or deque, the iterator is invalid after the erase. It's too much to go into here. For more information, see Item 9 in Scott Meyer's Effective STL book. Nicolai Josuttis' The C++ Standard Library would also be a very good investment. Chuck |