错误:'operator!='不匹配

Error: no match for 'operator!='

本文关键字:不匹配 operator 错误      更新时间:2023-10-16
void super::findTarget(list<int>Dlist,list<super>::iterator t){
while(t != Dlist.end()){
 double mypos[3];
 double target[3];
 double fpos[3];
 double speed;
 double range;
 double a, b, c, D;
 mypos[0]=this->x;
 mypos[1]=this->y;
 mypos[2]=this->z;
 range = this->range;
 target[0]=t->x;
 target[1]=t->y;
 target[2]=t->z;
 a = target[0]-mypos[0];
 b = target[1]-mypos[1];
 c = target[2]-mypos[2];
 D = sqrt( pow(a,2.0)+pow(b,2.0)+pow(c,2.0));
 Dlist.push_back(D);
   };
};

在第二行,while (t != Dlist.end(){,我收到以下错误:

C:\Users\Daniel\Desktop\project\super.cpp|369|error: no match for 'operator!=' in 't != Dlist.std::list<_Tp, _Alloc>::end>(('|

只是不允许在函数内执行此操作还是我错过了什么?

list<int>list<super>是两种不同的list。 不能将一个迭代器与另一个迭代器进行比较。

我认为你不应该比较list<int>::iteratorlist<super>::iterator.没有 != 运算符将这两种不同的类型作为参数。