[Dev-C++] Vector Erase Segmentation Fault
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <sab...@ve...> - 2005-07-02 01:33:45
|
Hello there,
I am having a few problems with the following code. It compiles fine but when
it is run, it gives a segmentation fault. I narrowed the error to where it
calls erase() on a vector. I've read that other people have this problem too
though I haven't seen any solution. Any help is greatly appreciated. BTW feel
free to make comments on the code design too!
Thanks
void EntityList::removeID(uint ID)
{
uint i = mEntityList.size() - 1;
std::vector<Entity*>::iterator itr;
for (itr = mEntityList.end(); itr > mEntityList.begin(); itr--)
{
if (mEntityList[i]->getID() == ID)
{
delete mEntityList[i];
mEntityList.erase(itr); //< Here's the problem.???
mCount--;
break;
}
else
{
i--;
}
}
}
|