Original Post
I have the following code which iterates through a list and erases an item where appropriate. The actual entry in the list is removed as planned, however the actual object is on deleted when I call: delete pParticle, even though pParticle is declared as a pointer. Anyone got any ideas??
void cParticleEmitter::Update(void)
{
cParticle *pParticle;
std::list<cParticle*>::iterator pIterator = pParticleListA->begin();
pParticle = *pIterator;
// update the life of the particle
pParticle->m_rLife -= g_timeElapsed / 1000.0f;
while (pIterator != pParticleListA->end())
{
//destroy the particle
if (pIterator != pParticleListA->begin() && pParticle.m_rLife <= 0)
{
delete (*pIterator);
delete pParticle;
pIterator = pParticleListA->erase(pIterator);
}
else
{
ApplyLinearForce(*pIterator);
++pIterator;
}
}
}