次のシナリオを検討してください。
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 で何に等しいでしょうか?
ありがとう...