檢查這個代碼:std :: list :: clear invalidate std :: list :: end iterator?
#include "stdafx.h"
#include <list>
int _tmain(int argc, _TCHAR* argv[])
{
std::list<int> mylist;
mylist.push_back(1);
std::list<int>::iterator i = mylist.end();
if(i == mylist.end())
printf("end is end\n");
mylist.clear();
if(i == mylist.end())
printf("never get here because Microsoft seems to "
"think the iterator is no longer safe.\n");
return 0;
}
現在,根據cplusplus.com這不應該是一個問題,而在釋放模式,我認爲這是很好,並沒有真正引起任何問題,但調試變得不可能的這只是保留而不讓我繼續。任何指針?
有趣。我以爲'.end'也是無效的,但文章卻說的是相反的。有趣的是,http://ideone.com/Y338N8按預期執行。 +1 –
這是非常有意義的,因爲我試圖移植到Windows的代碼是針對MacOS和Linux編寫的。兩者都在運行GCC,就像ideone一樣。我想這是一個庫錯誤。 –