Why the follwoing code is failing ?
typedef vector<SOCKET /*socket*/> UIConnection;
UIConnection::iterator itrUICon;
for ( itrUICon = m_ListUIConnection.begin();itrUICon != m_ListUIConnection.end();itrUICon++)
{
if (*itrUICon == nSock)
{
itrUICon = m_ListUIConnection.erase(itrUICon);
}
}
Probably because you are erasing the last item in the vector and then incrementing
itrUIConin the increment part of theforstatement when it is already equal to.end().Prefer using the
erase()/std::remove()idiom or at least move the increment out of theforstatement and only perform it if you didn’t preform anerase.