我正在尝试将一些值插入存储在共享内存中的boost :: interprocess :: map。
问题在于,当我尝试编译它时,它给了我“模糊调用重载函数”,我不知道为什么。以下是一些代码段:
#include <boost/interprocess/containers/map.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
typedef char * KeyType;
typedef long ValueType;
typedef std::pair<const char *, long> Type_Value;
typedef boost::interprocess::allocator<Type_Value, boost::interprocess::managed_shared_memory::segment_manager> ShmemAllocator;
typedef boost::interprocess::map<KeyType, ValueType, std::less<KeyType>, ShmemAllocator> MyMap;
...
MyMap * myMap = segment.construct<MyMap>("CyValoresRTD") //object name
(std::less<char *>() //first ctor parameter
,alloc_inst); //second ctor parameter
...
char * text = "some text";
long value = 1234;
myMap->insert( std::make_pair(text, value) );
这个插入调用给了我一些错误:
vcrtdserverimpl.cpp(445) : error C2668: 'boost::interprocess_container::map<Key,T,Pred,Alloc>::insert' : ambiguous call to overloaded function
with
[
Key=VCRTDServer::KeyType,
T=VCRTDServer::ValueType,
Pred=std::less<VCRTDServer::KeyType>,
Alloc=VCRTDServer::ShmemAllocator
]
p:\lib\boost_1_39_0\boost\interprocess\containers\container\map.hpp(407): could be 'std::pair<_Ty1,_Ty2> boost::interprocess_container::map<Key,T,Pred,Alloc>::insert(const std::pair<char *,long> &)'
with
[
_Ty1=boost::interprocess_container::containers_detail::rbtree<VCRTDServer::KeyType ,std::pair<const VCRTDServer::KeyType ,VCRTDServer::ValueType>,boost::interprocess_container::containers_detail::select1st<std::pair<const VCRTDServer::KeyType ,VCRTDServer::ValueType>>,std::less<VCRTDServer::KeyType>,VCRTDServer::ShmemAllocator>::iterator,
_Ty2=bool,
Key=VCRTDServer::KeyType,
T=VCRTDServer::ValueType,
Pred=std::less<VCRTDServer::KeyType>,
Alloc=VCRTDServer::ShmemAllocator
]
p:\lib\boost_1_39_0\boost\interprocess\containers\container\map.hpp(396): or 'std::pair<_Ty1,_Ty2> boost::interprocess_container::map<Key,T,Pred,Alloc>::insert(const std::pair<const Key,T> &)'
with
[
_Ty1=boost::interprocess_container::containers_detail::rbtree<VCRTDServer::KeyType ,std::pair<const VCRTDServer::KeyType ,VCRTDServer::ValueType>,boost::interprocess_container::containers_detail::select1st<std::pair<const VCRTDServer::KeyType ,VCRTDServer::ValueType>>,std::less<VCRTDServer::KeyType>,VCRTDServer::ShmemAllocator>::iterator,
_Ty2=bool,
Key=VCRTDServer::KeyType,
T=VCRTDServer::ValueType,
Pred=std::less<VCRTDServer::KeyType>,
Alloc=VCRTDServer::ShmemAllocator
]
while trying to match the argument list '(std::pair<_Ty1,_Ty2>)'
with
[
_Ty1=char *,
_Ty2=int
]
有没有人有任何想法?
答案 0 :(得分:1)
错误消息告诉您问题。
could be ...
::insert(const std::pair<char *,long> &)'
or ....
::insert(const std::pair<const Key,T> &)'
while trying to match the argument list '(std::pair<_Ty1,_Ty2>)'
with
[
_Ty1=char *,
_Ty2=int
]
std::map
键是const,插入对也是。使用std::string
作为密钥可能会更好。