Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 编译stl映射插入时出现问题_C++_Linux_Gcc_Stl - Fatal编程技术网

C++ 编译stl映射插入时出现问题

C++ 编译stl映射插入时出现问题,c++,linux,gcc,stl,C++,Linux,Gcc,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)); typedef std::map BlockMap; 区块地图商店; std::pairit; 它

我在编译以下代码时遇到问题:

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));
typedef std::map BlockMap;
区块地图商店;
std::pairit;
它=_store.insert(提示,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>&)
error:it=BlockStore::_-store.std::map::insert[with-Key=mUUID,_-Tp=Block*,_-Compare=std::less,_-Alloc=std::allocator](lb,((const-std::pair&)(&std::pair((const-std::pair*)(&std::make_-pair(_-T1,_-T2)[with-with-T1-mUUID,()))))()))))))41
/usr/include/c++/4.4/bits/stl_pair.h:68:注:候选项为:std::pair&std::pair::operator=(const std::pair&)

它似乎与赋值有关,因为如果我不将它赋值给“It”,它编译时不会出错。

接受提示的
insert
版本只返回迭代器,而不是一对。

接受提示的
insert
版本只返回迭代器,而不是一对。

首先,您的示例不完整-\u商店没有定义

第二,似乎您正试图为std::pair分配一个迭代器-无论如何,您为什么需要一个对

如果_store属于BlockMap类型,则以下操作应该可以正常工作:

块映射::迭代器
它=_store.insert(std::make_pair(entry.block_uid,block));

首先,您的示例不完整-\u商店没有定义

第二,似乎您正试图为std::pair分配一个迭代器-无论如何,您为什么需要一个对

如果_store属于BlockMap类型,则以下操作应该可以正常工作:

块映射::迭代器
它=_store.insert(std::make_pair(entry.block_uid,block));

什么是
\u-store
类型,以及
\u-store.insert
实际返回的是什么?\u-store实际上是一个区块图类型对不起。
\u-store
类型是什么,以及
\u-store.insert
实际返回的是什么?\u-store实际上是一个区块图类型对不起。当当,你说得对。我怎样才能让它使用提示并确定插入是否成功?我想你所能做的就是检查
\u store.size
是否增加了。该死,你说得对。我如何让它使用提示并找出插入是否成功?我想你所能做的就是检查
\u store.size
是否增加了。我需要知道插入是否成功,如果没有成功,那么我想访问已经在该位置存储的元素。i、 e.看起来我不能用提示来完成,必须使用返回一对的版本。如果您只需要指向元素的迭代器,可以使用带有提示的版本,因为如果存在迭代器,它将返回指向现有元素的迭代器-请参见否,我正在插入一个具有相同id的元素。如果该元素已经存在,我希望该元素的版本已经存在。如果insert成功,它似乎仍然返回一个迭代器,但它是指向我刚刚插入的元素的。在某些方面是毫无意义的。遗憾的是,没有一个提示版本可以返回该对。哦,好吧,这真的不会影响性能。我需要知道插入是否成功,如果没有成功,那么我想访问已经在该位置存储的元素。i、 e.看起来我不能用提示来完成,必须使用返回一对的版本。如果您只需要指向元素的迭代器,可以使用带有提示的版本,因为如果存在迭代器,它将返回指向现有元素的迭代器-请参见否,我正在插入一个具有相同id的元素。如果该元素已经存在,我希望该元素的版本已经存在。如果insert成功,它似乎仍然返回一个迭代器,但它是指向我刚刚插入的元素的。在某些方面是毫无意义的。遗憾的是,没有一个提示版本可以返回该对。哦,好吧,这真的不应该影响表演。