开发者

Erasing a pointer from a vector

I'm trying to erase a pointer to an object, but I keep crashing the console (PS2), I don't get any errors due to the way the console is set up, so I'm not quite sure what is going on.

I've listed the two lines that error, this didn't error until I added these lines.

    for(listIter = m_downDirectionList.begin(); listIter != m_downDirectionList.end(); listIter++)
    {
        Projectile* proj = dynamic_cast<Projectile*>(*listIter);

        if (proj->getZWorldCoord() >开发者_如何学Go= (defaultLevelDepth + zOffset))
        {
            proj->getPoolOwner()->releaseAProjectile(proj);
            //(*listIter) = NULL; // THIS ERRORS, also tried = 0.
            //listIter = m_downDirectionList.erase(listIter); // THIS ALSO ERRORS
        }

        else
        {
            (*listIter)->update(camera, zOffset);
        }
    }

What am I doing wrong?

Thanks.

EDIT: Clarification, just having this line.

listIter = m_downDirectionList.erase(listIter);

this also errors.


for(listIter = m_downDirectionList.begin(); listIter != m_downDirectionList.end(); )
    {
        Projectile* proj = dynamic_cast<Projectile*>(*listIter);

        if (proj->getZWorldCoord() >= (defaultLevelDepth + zOffset))
        {
            proj->getPoolOwner()->releaseAProjectile(proj);
            listIter = m_downDirectionList.erase(listIter);
        }

        else
        { //m_downDirectionList[p]->update(camera, zOffset);
            (*listIter)->update(camera, zOffset);
            listIter++
        }
    }


  m_downDirectionList.erase (listIter);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜