[英]Why does this iterator comparison fail?
Please see the following code:请看以下代码:
if((pos = find()) != _sym.end())
{
// do stuff
}
pos
is a scoped variable of type std::vector<T>::const_iterator
where T
is a POD-struct containing a pair of the same type of iterator. pos
是std::vector<T>::const_iterator
类型的作用域变量,其中T
是包含一对相同类型迭代器的 POD 结构。
_sym
is a private class member variable of type std::vector<T>
. _sym
是std::vector<T>
类型的私有类成员变量。
The example code throws a runtime assertion error with the message Expression: vector iterators incompatible
under Visual Studio 2013. The error occurs in <vector>
at line 240.示例代码引发运行时断言错误,并显示消息
Expression: vector iterators incompatible
under Visual Studio 2013。错误发生在<vector>
的第 240 行。
On the other hand, if I re-write the code:另一方面,如果我重新编写代码:
pos = find();
if(pos != _sym.end()) // do stuff
then, disco.然后,迪斯科。
I'm fairly sure that comparing an initialized iterator (such as end()
) with an uninitialized iterator causes this assertion;我相当确定将初始化的迭代器(例如
end()
)与未初始化的迭代器进行比较会导致此断言; What I don't understand is if/how pos
is not considered in an initialized state when the comparison operator is executed.我不明白的是,当执行比较运算符时,是否/如何不考虑
pos
处于初始化状态。
This might be relevant.这可能是相关的。
Why am I getting "vector iterators incompatible"? 为什么我得到“向量迭代器不兼容”?
I don't suppose find() changes _sym.end()?我不认为 find() 会改变 _sym.end()?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.