list iterator不可增量 [英] list iterator not incrementable
本文介绍了list iterator不可增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个旧项目,是使用visual studio 2003构建的,我最近重新编译它与vs2005。但是,在运行时,我得到以下错误:
I have an old project that was built using visual studio 2003 and I recompiled it with vs2005 recently. However, during runtime, I get the following error:
列表迭代器不可递增
我跟踪程序此函数:
void InputQueue::update()
{
list<PCB>::iterator iter;
list<PCB>::iterator iterTemp;
for(iter = begin(); iter != end(); iter++)
{
if(iter->arrivalTime == 0)
{
ReadyQueue::getInstance()->add(*iter);
iterTemp = iter;
iter++;
erase(iterTemp);
}
}
}
专家,这是VS调试器得到我。
I'm not a C++ expert and this is as far as the VS debugger got me. Could somebody explain to me what the problem is?
感谢
推荐答案
我将重写你的循环如下:
I would re-write your loop to be like the following:
while (iter != end())
{
if (iter->arrivalTime == 0)
{
ReadyQueue::getInstance()->add(*iter);
iter = erase(iter);
}
else
{
++iter;
}
}
现在您正在循环检查每个索引。
Now you are correctly looping through the list checking every index.
这篇关于list iterator不可增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文