在while循环中使用迭代器时,地址处的内存访问冲突(c ++)

时间:2016-02-10 07:16:01

标签: c++ c++11

所以当我尝试迭代“ObserverTree”(typedef std::map<std::string, std::vector<std::string>> ChannelTree; typedef std::map<std::string, ChannelTree> ObserverTree;)时我得到了这个错误

  

未知位置(0):“LoadTest”中的致命错误:地址处的内存访问冲突:0xfffffffffffffff8:故障地址处没有映射

在第observerIndicatorMap.insert(std::pair<std::string, int>(observerIterator->first, i));

如果此行被注释掉,我会收到此错误

  

未知位置(0):“LoadTest”中的致命错误:signal:SIGSEGV,si_code:0(地址处的内存访问冲突:0x00000080)

在第dataFieldIterator = channelIterator->second.begin();

这是整个方法:

void roboCorder::dataHandling::loadingUnit::RecordDataLoadingStrategy::createReplayObservers()
{
    int observerAmount = metaData.getObservertree().size();
    std::vector<roboCorder::activeUnits::ReplayObserverPtr>replayObservers(observerAmount);
    dataHandling::MetaData::ObserverTree::iterator observerIterator = metaData.getObservertree().begin();
for (int i = 0; i < observerAmount; i++, observerIterator++)
{
    replayObservers[i] = new activeUnits::ReplayObserver(observerIterator->first);
    observerIndicatorMap.insert(std::pair<std::string, int>(observerIterator->first, i));
    dataHandling::MetaData::ChannelTree::iterator channelIterator = observerIterator->second.begin();
    while (channelIterator != observerIterator->second.end())
    {
        //the second argument is the channel description but we dont save that so we just give the channel name as description.
        //replayObservers[i]->offerChannel(observerIterator->first, observerIterator->first);
        std::vector<std::string>::iterator dataFieldIterator;
        dataFieldIterator = channelIterator->second.begin();
        while (dataFieldIterator != channelIterator->second.end())
        {
            //replayObservers[i]->offerDataField(channelIterator->first, dataFieldIterator.operator * (),  firstValue?  , dataFieldIterator.operator * ());
            dataFieldIterator++;
        }
        channelIterator++;
    }
}

}

这是请求的LoadTest方法。正如你可以看到它的测试用例。 TestFileIdentifier是现有且有效的测试文件的路径。

BOOST_AUTO_TEST_CASE(LoadTest)
{
std::cout << std::endl << "--> LoadTest starts..." << std::endl;
Init loadTest;

try
{
    loadTest.dataHandlingController.loadRecord(TestFileIdentifier);
    std::cout << "done" << std::endl;
}
catch (std::exception e)
{
    std::cout << e.what() << std::endl;
    BOOST_FAIL("Loading caused an exception! Test Failed!");
}

}

loadRecord方法就在这里。还有一些方法缺少这就是为什么有一个虚拟输出。

roboCorder::dataHandling::DataReloaderListPtr roboCorder::dataHandling::DataHandlingController::loadRecord(std::string dataIdentifier)
{
loader->setRecordingIdentifier(dataIdentifier);
loader->loadMetaData();
loader->createReplayObservers();

return DataReloaderListPtr(); //dummy output.

}

0 个答案:

没有答案