[英]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
的文檔:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.