可以找到过载函数的实例。ERASE.ERASE与参数列表(向量)匹配,并且没有操作员“ =” ="匹配此操作数

发布于 2025-01-27 13:22:20 字数 1530 浏览 4 评论 0原文

因此,我正在处理此碰撞检测,并且得到4个错误:

  • e0349 no oterator“ =”这些操作数
  • e0349 e0349 no oterant no oterant'=“这些操作数
  • e0304 e0304 no offloaded函数的实例std :: vector :: vector< ___ty,_ alloc> :: alloc>: :erase [with _ty =,_alloc = std :: selicator<>]”匹配参数列表
  • e0304没有过载函数的实例” std :: vector< _ty,_ ty,_alloc&_Alloc> :: erase [with_alloc =,_alloc =,_alloc =,_alloc =, :分配器<>]“与参数列表匹配,

因此问题与迭代器有关,我不知道如何修复它们。

这是代码:

    //Collision detection
    vector<Animal>::iterator it;
    vector<Texture>::iterator it2;
    vector<Enemy>::iterator e_it;
    vector<Texture>::iterator e_it2;
    for (int i = 0; i < animal.size(); i++) {
        it = animal.begin() + i;   //error here
        it2 = animal_texture.begin() + i;
        SDL_Rect animal_collider = animal[i].getCollider();
        if (checkCollision(mCollider, animal_collider)) {
            score += 100 * mult;
            animal.erase(it);   //error here
            animal_texture.erase(it2);
            animal_num++;
        }
    }
    for (int i = 0; i < enemy.size(); i++) {
        e_it = enemy.begin() + i;   //error here
        e_it2 = enemy_texture.begin() + i;
        SDL_Rect enemy_collider = enemy[i].getCollider();
        if (checkCollision(mCollider, enemy_collider)) {
            score -= 50;
            --hp;
            enemy.erase(e_it);  //error here
            enemy_texture.erase(e_it2);
            enemy_num++;
        }
    }

So I'm working on this collision detection and I get 4 errors:

  • E0349 no operator "=" matches these operands
  • E0349 no operator "=" matches these operands
  • E0304 no instance of overloaded function "std::vector<_Ty, _Alloc>::erase [with _Ty=, _Alloc=std::allocator<>]" matches the argument list
  • E0304 no instance of overloaded function "std::vector<_Ty, _Alloc>::erase [with _Ty=, _Alloc=std::allocator<>]" matches the argument list

So the problem is with iterators and I have no idea how to fix them.

Here's the code:

    //Collision detection
    vector<Animal>::iterator it;
    vector<Texture>::iterator it2;
    vector<Enemy>::iterator e_it;
    vector<Texture>::iterator e_it2;
    for (int i = 0; i < animal.size(); i++) {
        it = animal.begin() + i;   //error here
        it2 = animal_texture.begin() + i;
        SDL_Rect animal_collider = animal[i].getCollider();
        if (checkCollision(mCollider, animal_collider)) {
            score += 100 * mult;
            animal.erase(it);   //error here
            animal_texture.erase(it2);
            animal_num++;
        }
    }
    for (int i = 0; i < enemy.size(); i++) {
        e_it = enemy.begin() + i;   //error here
        e_it2 = enemy_texture.begin() + i;
        SDL_Rect enemy_collider = enemy[i].getCollider();
        if (checkCollision(mCollider, enemy_collider)) {
            score -= 50;
            --hp;
            enemy.erase(e_it);  //error here
            enemy_texture.erase(e_it2);
            enemy_num++;
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文