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.
_sym
is a private class member variable of type 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.
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; What I don't understand is if/how pos
is not considered in an initialized state when the comparison operator is executed.
This might be relevant.
Why am I getting "vector iterators incompatible"?
I don't suppose find() changes _sym.end()?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.