【发布时间】:2010-09-30 19:05:44
【问题描述】:
请考虑以下场景:
map(T,S*) & GetMap(); //Forward decleration
map(T, S*) T2pS = GetMap();
for(map(T, S*)::iterator it = T2pS.begin(); it != T2pS.end(); ++it)
{
if(it->second != NULL)
{
delete it->second;
it->second = NULL;
}
T2pS.erase(it);
//In VS2005, after the erase, we will crash on the ++it of the for loop.
//In UNIX, Linux, this doesn't crash.
}//for
在我看来,在 VS2005 中,在“擦除”之后,迭代器将等于 end(),因此在尝试增加它时会崩溃。 编译器之间在此处呈现的行为中真的存在差异吗? 如果是这样,“擦除”之后的迭代器在 UNIX/Linux 中等于什么?
谢谢...
【问题讨论】:
标签: c++ linux visual-studio-2005 stl map