繁体   English   中英

如何删除'vector iterators incompatible'错误?

[英]How to remove the 'vector iterators incompatible' error?

我继承了几千行代码的责任,在许多地方都会在调试模式下生成'vector iterators incompatible'错误。 我目前正在使用Visual Studio Professional 2013版本12.0.31101.00 Update 4。

生成此错误的代码示例:

 int SqlHandler::VerifyColumnsInFilters (std::vector<TERMS*>*WhereFields,const int Idx, 
                                     std::vector<TABLES *>*Tables)
{
    int Status = 0; 
    for (std::vector<TERMS *>::iterator witer = WhereFields [Idx].begin (); 
    witer != WhereFields [Idx].end (); ++witer) 
    {

我已经尝试将上面的代码更改为:

std::vector<TERMS *>& whereVector = WhereFields[Idx];
for(std::vector<TERMS *>::iterator witer = whereVector.begin(); witer != whereVector.end(); ++witer)

和这个:

std::vector<TERMS *>& whereVector = WhereFields[Idx];
for(auto& termsPtr : whereVector)

在每种情况下都会生成相同的向量迭代器不兼容错误。 忽略C风格分配缓冲区和向量的奇怪混合。 在调试模式下导致错误的原因是什么? 此代码似乎在发布模式下正确执行,我真的希望能够在调试器中逐步执行它。

谢谢

编辑以响应注释:WhereFields [Idx]是for循环之前的有效向量。

产生此错误的代码的完整示例是:

int SqlHandler::VerifyColumnsInFilters (std::vector<TERMS *>*WhereFields, 
                                     const int Idx, 
                                     std::vector<TABLES *>*Tables)
{
    int Status = 0; 

    std::vector<TERMS *>& whereVector = WhereFields[Idx];
    for(auto& termsPtr : whereVector)
    {
        for(std::vector<Term *>::iterator iter = termsPtr->T.begin();
            iter != termsPtr->T.end(); ++iter)
        {
            if((*iter)->sub_q >= 0)
            {
                continue;
            }           
        }
    }

循环中的任何内容都不会以任何方式更改实际矢量。

整个错误消息是:向量迭代器不兼容,从c:\\ Program Files(x86)\\ Microsoft Visual Studio 12.0 \\ VC \\ include \\ vector中的此代码生成

#if _ITERATOR_DEBUG_LEVEL == 2
    void _Compat(const _Myiter& _Right) const
        {   // test for compatible iterator pair
        if (this->_Getcont() == 0
            || this->_Getcont() != _Right._Getcont())
            {   // report error
            _DEBUG_ERROR("vector iterators incompatible");
            _SCL_SECURE_INVALID_ARGUMENT;
            }
        }

我的通灵调试技巧告诉我, Idx并没有指向WhereFields指向的向量数组的有效成员(最可能的猜测是向量已经被破坏但是对它的引用仍然存在 - 它可能仍然显示有效但是实际上死了)。 您应该检查的值调用点Idx并确认载体已在内部被正确构造WhereFields阵列。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM