A
Angus
Hello
I have a vector<int> (aRemovecoll) which is a list of the indexes to
be removed from another vector. The other vecotr contains an object -
I will call it SomeObject. So the other vecotr is a
vector<SomeObject>.
I have created a function like this so far:
UINT uNumElements = aRemoveColl.GetSize();
vector<T>::reverse_iterator obCurrent = rbegin(); // work from
end back
for (UINT nLoop = uNumElements; nLoop != 0; nLoop--)
{
// Work from end of vecotr to beginning so that iterators are
always valid
intuIndex;
aRemoveColl.GetAt(nLoop, uIndex);
advance(obCurrent, uIndex);
erase(obCurrent);
}
My thinking is that I need to erase from the end backwards because
otherwise the iterator will become invalid. But then advance doesn't
see right. Is there a backward? Or should I be doing this totally
differently?
I have a vector<int> (aRemovecoll) which is a list of the indexes to
be removed from another vector. The other vecotr contains an object -
I will call it SomeObject. So the other vecotr is a
vector<SomeObject>.
I have created a function like this so far:
UINT uNumElements = aRemoveColl.GetSize();
vector<T>::reverse_iterator obCurrent = rbegin(); // work from
end back
for (UINT nLoop = uNumElements; nLoop != 0; nLoop--)
{
// Work from end of vecotr to beginning so that iterators are
always valid
intuIndex;
aRemoveColl.GetAt(nLoop, uIndex);
advance(obCurrent, uIndex);
erase(obCurrent);
}
My thinking is that I need to erase from the end backwards because
otherwise the iterator will become invalid. But then advance doesn't
see right. Is there a backward? Or should I be doing this totally
differently?