So I am seg faulting when I run this function
class vector <Record<value> >::iterator itr = records.begin();
for (; itr != records.end(); ++itr) {
if (itr->isSelected()) {
itr = records.erase(itr);
recordSize--;
}
}
where my vector is of vector <Record <value> > records; and the function isSelected() is just a boolean that is either true when the object is selected or false when its not.
Can someone help me please, I don’t see the problem with doing it this way
In the case where you’re deleting the last element,
itrwill first berecords.end()because that’s whatrecords.erase()will return, and then you’re incrementing it with++itr. Try: