编译 stl 地图插入时出现问题
我在编译以下代码时遇到问题:
typedef std::map<mUUID, block_ptr_t> BlockMap;
BlockMap _store;
std::pair< BlockMap::iterator, bool > it;
it = _store.insert(hint, std::make_pair(entry.block_uid, block));
错误是:
error: no match for ‘operator=’ in ‘it = BlockStore::_store.std::map<_Key, _Tp, _Compare, _Alloc>::insert [with _Key = mUUID, _Tp = Block*, _Compare = std::less<mUUID>, _Alloc = std::allocator<std::pair<const mUUID, Block*> >](lb, ((const std::pair<const mUUID, Block*>&)(& std::pair<const mUUID, Block*>(((const std::pair<mUUID, Block*>&)((const std::pair<mUUID, Block*>*)(& std::make_pair(_T1, _T2) [with _T1 = mUUID, _T2 = Block*](block))))))))’
/usr/include/c++/4.4/bits/stl_pair.h:68: note: candidates are: std::pair<std::_Rb_tree_iterator<std::pair<const mUUID, Block*> >, bool>& std::pair<std::_Rb_tree_iterator<std::pair<const mUUID, Block*> >, bool>::operator=(const std::pair<std::_Rb_tree_iterator<std::pair<const mUUID, Block*> >, bool>&)
它似乎与分配有关,因为如果我不将其分配给“it”,它的编译不会出现错误。
I'm having trouble compiling the following code:
typedef std::map<mUUID, block_ptr_t> BlockMap;
BlockMap _store;
std::pair< BlockMap::iterator, bool > it;
it = _store.insert(hint, std::make_pair(entry.block_uid, block));
The error is:
error: no match for ‘operator=’ in ‘it = BlockStore::_store.std::map<_Key, _Tp, _Compare, _Alloc>::insert [with _Key = mUUID, _Tp = Block*, _Compare = std::less<mUUID>, _Alloc = std::allocator<std::pair<const mUUID, Block*> >](lb, ((const std::pair<const mUUID, Block*>&)(& std::pair<const mUUID, Block*>(((const std::pair<mUUID, Block*>&)((const std::pair<mUUID, Block*>*)(& std::make_pair(_T1, _T2) [with _T1 = mUUID, _T2 = Block*](block))))))))’
/usr/include/c++/4.4/bits/stl_pair.h:68: note: candidates are: std::pair<std::_Rb_tree_iterator<std::pair<const mUUID, Block*> >, bool>& std::pair<std::_Rb_tree_iterator<std::pair<const mUUID, Block*> >, bool>::operator=(const std::pair<std::_Rb_tree_iterator<std::pair<const mUUID, Block*> >, bool>&)
It seems to be related to the assignment because if I don't assign it to "it" it compiles without error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
接受提示的
insert
版本仅返回一个迭代器,而不是一对。The version of
insert
that takes a hint returns only an iterator, not a pair.首先,您的示例不完整 - _store 没有定义。
其次,您似乎正在尝试将迭代器分配给 std::pair - 无论如何,为什么您需要一对?
如果 _store 是 BlockMap 类型,则以下内容应该有效:
<代码>
BlockMap::iterator it;
it = _store.insert(std::make_pair(entry.block_uid, block));
First of all, your example is incomplete - _store is defined nowhere.
Second, it seems you are trying to assign an iterator to a std::pair - why do you need a pair, anyway?
The following should work, provided that _store is of type BlockMap:
BlockMap::iterator it;
it = _store.insert(std::make_pair(entry.block_uid, block));