Can a C++ std::list iterator move past the end? -
for(std::list<myclass *>::iterator = m_currentjobs.begin(); != m_currentjobs.end(); ++it) { request = *it; if(request != null) { printf(request->status()); } delete request; m_currentjobs.erase(it); }
is possible iterator point garbage data beyond end of list?
you make iterator invalid erasing it.
you may change loop to:
std::list<myclass *>::iterator = m_currentjobs.begin(); while(it != m_currentjobs.end()) { // ... = m_currentjobs.erase(it); }
and answer question: yes possible have invalid iterator (not limited iterators past end). using these involves undefined behavior.
Comments
Post a Comment