[当我尝试迭代这样的地图的Vector时,出现错误:
invalid operands to binary expression ('vector<idType>' (aka 'vector<unsigned long long>') and 'std::reverse_iterator<__gnu_cxx::__normal_iterator<unsigned long long *, std::vector<unsigned long long, std::allocator<unsigned long long> > > >')
system_error:319:3: note: candidate function not viable: no known conversion from 'vector<idType>' (aka 'vector<unsigned long long>') to 'const std::error_code' for 1st argument
system_error:323:3: note: candidate function not viable: no known conversion from 'vector<idType>' (aka 'vector<unsigned long long>') to 'const std::error_code' for 1st argument
system_error:327:3: note: candidate function not viable: no known conversion from 'vector<idType>' (aka 'vector<unsigned long long>') to 'const std::error_condition' for 1st argument
system_error:331:3: note: candidate function not viable: no known conversion from 'vector<idType>' (aka 'vector<unsigned long long>') to 'const std::error_condition' for 1st argument
thread:280:3: note: candidate function not viable: no known conversion from 'vector<idType>' (aka 'vector<unsigned long long>') to 'thread::id' for 1st argument
guiddef.h:176:15: note: candidate function not viable: no known conversion from 'vector<idType>' (aka 'vector<unsigned long long>') to 'const GUID' (aka 'const _GUID') for 1st argument
postypes.h:221:5: note: candidate template ignored: could not match 'fpos' against 'vector'
...
iterator_range_core.hpp:662:9: note: candidate template ignored: could not match 'iterator_range' against 'vector'
iterator_range_core.hpp:672:9: note: candidate template ignored: could not match 'iterator_range' against 'vector'
stl_queue.h:342:5: note: candidate template ignored: could not match 'queue' against 'vector'*
MyGraphBuilder::MyGraphBuilder() // default Constructor
{
m_Data = new modelData;
WayMap MyWayMap = m_Data->getWayMap();
WayMap::iterator it;
// it->first ;// (key = WayID)
// it->second ;// (Value WayData.nodRefList[idType])
// map <source distination weight(distance) >
for ( it = MyWayMap.begin(); it != MyWayMap.end(); it++ ) // Loop the Whole Way Map
{
for(it->second.nodeRefList.begin();it->second.nodeRefList != it->second.nodeRefList.rbegin()-1;it->second.nodeRefList++)// Loop The Whole Nodes of Each way
;
}
}
这些评论已为您提供了您已经需要的所有提示。
如果我们假设it->second.nodeRefList
是一个容器(而不是迭代器),并且行号对应于内部循环,则内部循环看起来或多或少像]
for(auto j = it->second.nodeRefList.begin(); j != it->second.nodeRefList.end(); ++j)
; // do something with node iterator (j)
更好,请使用Range-based for loop
for (auto &node : it->second.nodeRefList)
; // do something with node
要使用连续元素计算距离,可以使用两个迭代的迭代器进行迭代
auto &nodes = it->second.nodeRefList;
for (auto i1 = nodes.begin(), i2 = i1 + 1; i2 != nodes.end(); ++i1, ++i2) {
auto dist = euclidean_distance(*i1, *i2);
// ...
}