【发布时间】:2009-05-16 03:04:58
【问题描述】:
我有一个循环
for(aI = antiviral_data.begin(); aI != antiviral_data.end();)
{
for(vI = viral_data.begin(); vI != viral_data.end();)
{
if((*aI)->x == (*vI)->x && (*aI)->y == (*vI)->y)
{
vI = viral_data.erase(vI);
aI = antiviral_data.erase(aI);
}
else
{
vI++;
aI++;
}
}
}
但是当 antiviral_data 包含一个项目时,我会收到一个错误“vector iterator not dereferencable”。为什么会出现此错误,我在哪里取消引用无效的迭代器?
注意:到目前为止,仅当 if() 语句为假时才会发生错误。我不知道如果 if() 语句为真会发生什么。
【问题讨论】: