【发布时间】:2017-07-23 23:03:58
【问题描述】:
这是我的代码的摘录:
std::map<int, std::pair< const int, const std::vector<POINT_3d> > > m_srcHitData;
void addHit( const int edgeId, const int hit )
{
m_srcHitData[edgeId] = std::make_pair( hit, std::vector<POINT_3d>() );
}
我不断收到错误:
stl_pair.h(180): error: no operator "=" matches these operands operand types are: const std::vector<POINT_3d, std::allocator<POINT_3d>> = const std::vector<POINT_3d, std::allocator<POINT_3d>> second = __p.second; ^ detected during instantiation of "std::pair<_T1, _T2> &std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2> &)
这是什么意思?我尝试了不同的方法,但仍然得到这个或类似的错误。谢谢!
【问题讨论】:
-
不要使用
m_srcHitData[edgeId] = std::make_pair( hit, std::vector<POINT_3d>() );,而是尝试使用m_srcHitData[edgeId].insert( std::make_pair( hit, std::vector<POINT_3d>() );,看看这是否有效或给你一个不同的编译器错误。嗯,现在我考虑到该插入可能不适用于m_srcHitDat[idx]与 einpoklum 所说的相同的问题,因为 constness。 -
@Francis 您实际上并不是指 m_srcHitData[edgeId].insert() ,对吧?它应该是 m_srcHitData.insert ( pair (edgeId, ...) )。这行得通,谢谢!
-
好吧,当我回答时,我的 IDE 没有打开。所以我试图摆脱记忆......将我的答案作为构建地图的适当方式。