[英]List Iterator not dereferencable
I have been looking for the same problem I have with iterators; 我一直在寻找与迭代器相同的问题; and I found a lot of topics with almost the same title, and similar problems, but mine is a little bit different.
我发现很多主题几乎相同的标题,也有类似的问题,但是我的主题略有不同。
I'm trying to get the *iterator at a specific position, but I get the error: "list iterator not deferencable" at run time, here is my code: 我正在尝试将* iterator放置在特定位置,但出现错误:“在运行时不可列出列表迭代器”,这是我的代码:
CompetidorFormula2000* retornarCompetidorF2000(int pos){
list<Competidor*>::iterator itr=miLista.begin();
CompetidorFormula2000* f1=new CompetidorFormula2000();
if(pos>0 && pos<=miLista.size()){
advance(itr,pos);
}
f1=(CompetidorFormula2000*) (*itr);
return f1;
delete f1;
}
If pos
equals miLista.size()
then you will get an iterator to the end of the list, the same iterator you get when you call miLista.end()
. 如果
pos
等于miLista.size()
那么您将获得一个迭代器到列表的末尾,即调用miLista.end()
时获得的迭代器。 An iterator to the end of the list is not dereferenceable . 列表末尾的迭代器不可取消引用 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.