I'm doing a remake of Yoshi's Island and I'm using a vector to keep track of instances. However, I'm having trouble removing particular elements from the vector.
This is my best shot so far:
for(vector<ShyGuy*>::iterator it = m_shyguylist->begin(); it != m_shyguylist->end(); ++it)
{
if(*it == shyguyptr)
{
m_shyguylist->erase(it);
}
}
The program crashes on an assertion failure after the first instance gets deleted. I know this is not the way to do it, so:
Can anyone show me a viable way to remove elements from a vector?
oh yes, I feel silly now for saying it was fine. erase should return the new end, so then it will then it will only continue to check the last element. If you don't actually need to use delete, you could use remove from <algorithm>