T
TBass
So I have a class:
class Client
{
unsigned int ClientID;
....
};
class MyListenSocket
{
...
AddClient( Client *pClient);
RemoveClient( unsigned int ID );
std::list<Client> m_listClients;
};
To add clients to the list, AddClient is called:
MyListenSocket::AddClient( Client *pClient )
{
m_listClients.push_back( *pClient );
}
But a client can be erased from anywhere on the list. I wrote this
function:
MyListenSocket::RemoveClient( unsigned int ID )
{
std::list<Client>::iterator it;
for( it = m_listClients.begin();
it != m_listClients.end();
++it )
{
if ( it->ClientID() == ID )
{
m_listClients.erase( it );
break;
}
}
}
The problem is that this seems to corrupt the heap in my program. I
know that the iterator is corrupted when I use the erase command, but
why would that corrupt the heap?
Is this not the way to delete an item from the middle of a list?
Should I not be using ::list for this type of purpose?
Thanks in advance,
Tom Junior
class Client
{
unsigned int ClientID;
....
};
class MyListenSocket
{
...
AddClient( Client *pClient);
RemoveClient( unsigned int ID );
std::list<Client> m_listClients;
};
To add clients to the list, AddClient is called:
MyListenSocket::AddClient( Client *pClient )
{
m_listClients.push_back( *pClient );
}
But a client can be erased from anywhere on the list. I wrote this
function:
MyListenSocket::RemoveClient( unsigned int ID )
{
std::list<Client>::iterator it;
for( it = m_listClients.begin();
it != m_listClients.end();
++it )
{
if ( it->ClientID() == ID )
{
m_listClients.erase( it );
break;
}
}
}
The problem is that this seems to corrupt the heap in my program. I
know that the iterator is corrupted when I use the erase command, but
why would that corrupt the heap?
Is this not the way to delete an item from the middle of a list?
Should I not be using ::list for this type of purpose?
Thanks in advance,
Tom Junior