[英]'vector iterators incompatible'
std::vector<Enemy*>::iterator it;
for(it;it!=tracked.end();it++){
(*it)->update(timeSinceLastFrame);
}
tracked
is the vector: tracked
是向量:
std::vector<Enemy*>
Why am I getting this error? 为什么我收到此错误? (please say if I haven't included enough details)
(如果我没有提供足够的细节,请说明)
You never initialized the iterator. 你从来没有初始化迭代器。
for(std::vector<Enemy*>::iterator it = tracked.begin();it!=tracked.end();it++){
(*it)->update(timeSinceLastFrame);
}
Many implementations (such as VC++, which you appear to be using) perform checks in debug to make sure that when two iterators are compared, they belong to the same object. 许多实现(例如VC ++,您似乎正在使用)在调试中执行检查,以确保在比较两个迭代器时,它们属于同一个对象。 A default constructed iterator does not belong to any particular instance, and as such the
it != tracked.end()
check will fail with that error. 默认构造的迭代器不属于任何特定实例,因此
it != tracked.end()
检查将失败并显示该错误。
You haven't initialized it
. 你还没有初始化
it
。 Try this: 尝试这个:
std::vector<Enemy*>::iterator it;
for(it=tracked.begin();it!=tracked.end();it++){
(*it)->update(timeSinceLastFrame);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.