【发布时间】:2014-01-01 20:26:00
【问题描述】:
我目前正在用 cinder 编写一个太空射击游戏来学习 c++。我正在检查激光和敌人之间的碰撞。
void ParticleController::CheckCollisions()
{
for(std::list<Enemy>::iterator e = enemys_.begin(); e != enemys_.end();)
{
for(std::list<LaserParticle>::iterator p = laserParticles_.begin(); p != laserParticles_.end();)
{
if(e->GetBoundingBox().intersects(p->GetBoundingBox()))
{
e = enemys_.erase(e);
p = laserParticles_.erase(p);
}
else
++p;
}
++e;
}
}
但我收到错误“列表迭代器不可递增”。我之前遇到过这个错误,但这次我似乎无法修复它。
【问题讨论】:
-
当您尝试比 .end() 进一步增加时,您可能会收到此错误
-
@Elliot Robinson 该问题的答案不适用于我的情况
-
这应该是所有敌人都被激光击中的情况下的精确应用,因为您的
++e不以e != enemys_.end()为条件