检查这个代码: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一样。我想这是一个库错误。 –