jc01rho의 일상잡다

STL Iterator erase시 "vector iterators incompatible" 본문

컴퓨터/C & C++

STL Iterator erase시 "vector iterators incompatible"

jc01rho 2011. 7. 19. 12:55

[발생한 Error 내용]

---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!

Program: d:\temp_01\stl_vectordeleteinstanceiter(2)\Debug\DeleteIt.exe
File: c:\program files\microsoft visual studio 9.0\vc\include\vector
Line: 251

Expression: vector iterators incompatible

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)
---------------------------
중단(A) 다시 시도(R) 무시(I)
---------------------------

[수정한 내용]-전체 소스는 첨부파일 참조

========================================================

for( it = m_Table.begin( ); it != m_Table.end( ); )
{
if ( (*it).iA == 20 )
{
//m_Table.erase(it); //<=====VS2003에서 실행되지만 VS2008에서는 실행시 Error
it = m_Table.erase(it); //<=====VS2008에서는 정상적으로 실행됨

}
else
{
++it;
}

}


Comments