c++ - 列表迭代器不可取消引用

标签 c++ list iterator

我一直在寻找与迭代器相同的问题;我发现了很多标题几乎相同、问题相似的主题,但我的有点不同。

我试图在特定位置获取 *iterator,但出现错误: “list iterator not deferencable”在运行时,这是我的代码:

 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;
    }

最佳答案

如果 pos 等于 miLista.size() 那么您将获得一个指向列表末尾的迭代器,与调用 miLista 时获得的迭代器相同.end()。列表末尾的迭代器不可取消引用

关于c++ - 列表迭代器不可取消引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11002140/

相关文章:

c++ - 如何获取 QTableView 的标题列表?

c++ - 制作对 inner_product 的自定义调用 (C++ STL)

python - 计算数组列表的计数百分比

python - 使用 .format() 格式化具有字段宽度参数的列表

c++ - 在 Android 上移植 native C++ 非静态二进制文件

c++ - Opencv 2.2 人脸检测最大尺寸

java - 如何从列表中检索所有最大值?

c++ - std::copy raw data to cout in hex format using ostream_iterator<uint8_t> 打印出未格式化的数据。为什么?

c++ - 通过传递输出迭代器从函数填充 std::[container]

c++ - 操作数 "="和 "!="的 vector 错误迭代器