请考虑以下场景:
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 中等于什么?
谢谢...