我正在尝试为我的项目符号使用列表。每当我运行我的更新项目符号代码时,它都会给我这个错误:
错误 1 错误 C2662:“Bullet::detectCollision”:无法将“this”指针从“const Bullet”转换为“Bullet &”
我的列表:
std::list<Bullet> bullet_list;
我的更新代码:
std::list<Bullet>::const_iterator cIter;
for ( cIter = bullet_list.begin( ); cIter != bullet_list.end( ); cIter++ )
{
if((*cIter).detectCollision(monster.position,monster.getHeight(),monster.getWidth()))
{
//Do stuff here
}
if ((*cIter).detectCollision(boss.getPosition(),boss.getHeight(),boss.getWidth()))
{
//Do stuff here
}
}
我检测碰撞代码:
bool Bullet::detectCollision(Vector objTwo,int heightT,int widthT)
{
if(position.getVectorX() >= objTwo.getVectorX() - (widthT/2) && position.getVectorX() <= objTwo.getVectorX() + (widthT/2)
&& position.getVectorY() >= objTwo.getVectorY() - (widthT/2)&& position.getVectorY() <= objTwo.getVectorY() + (heightT/2) && alive)
{
return false;
}
return true;
}