繁体   English   中英

调试断言失败! 表达式列表迭代器不兼容

[英]debug assertion failed! expression list iterators incompatible

我正在做一个分配工作,我用C ++实现了一个字典(ADT)。 我最初是用Xcode编写程序的,并且看起来一切正常。 但是,我最近发现平地机使用Visual Studio 2010,因此我尝试确保我的代码也可以在VS2010中使用。

我现在遇到的问题是哈希表的remove()函数。 基本上,我使用列表的向量并遍历列表以删除冲突条目。 但是,现在当我尝试测试此remove()函数时,出现以下错误: debug assertion failed! expression list iterators incompatible debug assertion failed! expression list iterators incompatible 我试图浏览有关断言的Visual C ++文档,并且一切看起来都应该正常工作。

这是我的代码:

///**DELETE***////  
void remove(string key) {
    size_t index = hashString(key);
    list<Entry>& entry = table.at(index);
        for(typename list<Entry>::iterator it = entry.begin();
            it != entry.end();
            /**/)
        {
            if (it->data == key) {
                table[index].erase(it);
            } else
                it++;
        }
    //entry not found
    cout << "Error: Cannot Delete... No Such Entry"<< endl;
}

您忽略了erase的返回值,这很可疑。 如果将包含erase调用的行更改为此,这行得通吗?

it = table[index].erase(it);

或者确实是:

it = entry.erase(it);

请参阅list::erase的文档:

http://www.cplusplus.com/reference/list/list/erase

暂无
暂无

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

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