0

I noticed I get a "Vector Iterators Incompatible" error when I try to compare two different copies of a vector.

There are enough questions about this error to find how to solve it:

Why am I getting “vector iterators incompatible”?
C++ STL vector iterators incompatible
Debug Assertion : Vector iterators incompatible (C++)
Vector Iterators Incompatible

My question is: is it possible to either disable the check in debug or enable the check in release to make both configurations behave the same way?

My question is NOT: What the error means, what causes it, or how to resolve it.


Additional Details

My compiler options, in debug mode, are:

/ZI /nologo /W3 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yu"StdAfx.h" /Fp"Debug\test.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /analyze- /errorReport:queue 

And, in release mode:

/Zi /nologo /W3 /WX- /O2 /Oi /Oy- /GL /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm- /EHsc /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Yu"StdAfx.h" /Fp"Release\test.pch" /Fa"Release\" /Fo"Release\" /Fd"Release\vc100.pdb" /Gd /analyze- /errorReport:queue 

Here is a little snippet of code to reproduce the error:

#include <vector>
#include <iostream>
#include <string>

using namespace std;

class foo{
    public:
        const std::vector<int> getVec(){return myVec;} //other stuff omitted

    private:
        std::vector<int> myVec;
};

int main(int argc, char* argv[])
{
    foo myFoo = foo();

    std::vector<int>::const_iterator i = myFoo.getVec().begin();
    while( i != myFoo.getVec().end())
    {
       //do stuff
       ++i;
    }

    string s;
    cin >> s;

    return 0;
}
Pierre
  • 1,942
  • 3
  • 23
  • 43
  • 1
    I took a liberty of doing a major edit of the question to reflect its meaning more clearly. Please feel free to revert the edit, if you feel that it's not making the things better. – AMA Jun 07 '18 at 10:08
  • 1
    [How to put assert into release builds in C/C++](https://stackoverflow.com/q/620892/1332041) – acraig5075 Jun 07 '18 at 10:11
  • 1
    The short answer is: The checks can be enabled or disabled in either mode (Debug/Release) using the [_ITERATOR_DEBUG_LEVEL](https://msdn.microsoft.com/en-us/library/hh697468.aspx) macro. (The longer answer was lost when the question was closed). – Bo Persson Jun 07 '18 at 10:26
  • @BoPersson It works to hide the error when we are in debug mode (_ITERATOR_DEBUG_LEVEL=0) but we cannot do the opposite in release mode (_ITERATOR_DEBUG_LEVEL=2). We get an error C1189: _ITERATOR_DEBUG_LEVEL > 1 is not supported in release mode. – Pierre Jun 07 '18 at 12:04

0 Answers0