J
John Smith
Today I experienced something very very weird with STL.
The code snippet below should work, but it doesn't with Microsoft VC++ 6.0.
Ok what I have is a list of network connections. The code below removes one
of these connections from a temporary list. It goes through all the items to
find the right connection and removes it by erasing with the matching
iterator.
However what happens is that the item stays in the list after beeing deleted
but another one is deleted though. The size of the list goes down by 1 after
the erase function but the item still stays there. This was verified by
printing out the list after the erase function was called.
Can anyone explain this? My first thought is that it must be a bug in the
compiler.
I solved it by using list::remove() instead.
The list is of type list<CClientConnection *>
void CConnectionList::RemoveConnectionFromInProcessList(CClientConnection
*pC)
{
CConnectionList::iterator it;
// Remove connection from the temporary list
for (it = m_InProcessList.begin(); it != m_InProcessList.end(); it++)
{
if (*it = pC)
{
m_InProcessList.erase(it);
break;
}
}
}
Thanks in advance.
-- John
The code snippet below should work, but it doesn't with Microsoft VC++ 6.0.
Ok what I have is a list of network connections. The code below removes one
of these connections from a temporary list. It goes through all the items to
find the right connection and removes it by erasing with the matching
iterator.
However what happens is that the item stays in the list after beeing deleted
but another one is deleted though. The size of the list goes down by 1 after
the erase function but the item still stays there. This was verified by
printing out the list after the erase function was called.
Can anyone explain this? My first thought is that it must be a bug in the
compiler.
I solved it by using list::remove() instead.
The list is of type list<CClientConnection *>
void CConnectionList::RemoveConnectionFromInProcessList(CClientConnection
*pC)
{
CConnectionList::iterator it;
// Remove connection from the temporary list
for (it = m_InProcessList.begin(); it != m_InProcessList.end(); it++)
{
if (*it = pC)
{
m_InProcessList.erase(it);
break;
}
}
}
Thanks in advance.
-- John