【问题标题】:converting from iterator to the object c++从迭代器转换为对象 c++
【发布时间】:2015-12-22 09:18:18
【问题描述】:

我有一个遍历列表的迭代器,我尝试将迭代器转换为对象。

std::list<XMLObjects>::const_iterator objectsIterator;
for (objectsIterator = frame->getObjectsList().begin(); objectsIterator != frame->getObjectsList().end(); ++objectsIterator)
    {
      XMLObjects object =(*objectsIterator);
    }

但我得到一个错误:

OR_Comparator.exe 中 0x00007FFA9A658384 处未处理的异常: Microsoft C++ 异常:内存位置的 std::bad_alloc 0x0000007C0196C490.

我可以以一种好的方式转换它吗?

【问题讨论】:

  • 你有什么错误?
  • OR_Comparator.exe 中 0x00007FFA9A658384 处未处理的异常:Microsoft C++ 异常:内存位置 0x0000007C0196C490 处的 std::bad_alloc。
  • FWIW,*objectsIterator 周围的括号不需要。
  • 哇,将近 2 年之后您回来包含错误?我印象深刻。

标签: c++ list iterator


【解决方案1】:

std::list<XMLObjects>::iterator objectsIterator;

而不是

std::list<XMLObjects>::const_iterator objectsIterator;

然后在for中写:

xmlObjects &gt=(*objectsIterator);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-08
    • 2011-03-24
    • 2021-09-04
    • 2021-12-30
    • 2011-11-22
    • 2012-09-13
    • 2019-10-23
    相关资源
    最近更新 更多