小编Bro*_*dup的帖子

二进制“==”:未找到采用“Enemy”类型左侧操作数的运算符(或没有可接受的转换)

我正在制作一个游戏,我正在尝试使用 bool shouldDie == true 找到敌人。我有一个 Enemy std::list,我个人不知道代码有什么问题。如果敌人有 shouldDie == true 我只会播放动画。希望您能帮助我理解为什么我会收到错误消息。

此外,我没有重载 == 运算符,我在网上搜索过,但不确定是否有必要...

bool foundEnemy(Enemy& enemy)
{
    return enemy.shouldDie == true;
}
Run Code Online (Sandbox Code Playgroud)
void Enemy::PlayDeathAnimation(std::list<Enemy>& enemies)
{
    dead = true;

    auto it = std::find_if(enemies.begin(), enemies.end(), foundEnemy); // where I think the error is
    auto enemy = std::next(it, 0);

    if (animationClock.getElapsedTime().asSeconds() >= 0.05f)
    {
        enemy->icon.setTextureRect(animationFrames[animationCounter]);
        if (animationCounter >= 8)
        {
            enemies.remove(*enemy);
        }
        animationCounter++;
        animationClock.restart();

    }
}
Run Code Online (Sandbox Code Playgroud)
class Enemy : public Entity
{
public:
    Enemy() {}
    Enemy(sf::Vector2f position, sf::Texture* texture,Player* target); …
Run Code Online (Sandbox Code Playgroud)

c++ stl

1
推荐指数
1
解决办法
60
查看次数

标签 统计

c++ ×1

stl ×1