Hi,
I have a vector of type TReferenceItem(structure) and I would like to erase
one of the TReferenceItem inside the vector based on 2 criteria of the
TReferenceItem
vector<TReferenceItem>::iterator itVec;
for ( i = 0, itVec = m_RefItemVec.begin() ; itVec != m_RefItemVec.end();
itVec++, i++)
{
nCompIDServer = memcmp(m_RefItemVec[i].IDServer, AIDServer,
sizeof(TARSIDServer));
nCompIDUser = (m_RefItemVec[i].IDUser == AIDUser)?0:1;
if (nCompIDServer == 0 && nCompIDUser == 0) // If the 2 criteria match
{
m_RefItemVec.erase(itVec); // Delete the reference
}
}
Actually my problem is simple I whant to get through each element of my
vector and if the element match my conditions I want to remove it.
I tried the above code but it doesn't work because if the TReferenceItem to
remove is the last element when i do : m_RefItemVec.erase(itVec) the
iterator.end is modifief so that my stop condition is never realized and i
have a forever loop.
What is the solution ?