可以找到过载函数的实例。ERASE.ERASE与参数列表(向量)匹配,并且没有操作员“ =” ="匹配此操作数
因此,我正在处理此碰撞检测,并且得到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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论