简体   繁体   English

从向量中删除指针

[英]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. 我正在尝试删除指向对象的指针,但我不断使控制台(PS2)崩溃,由于控制台的设置方式,我没有收到任何错误,因此我不确定发生了什么。

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() >= (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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM