2012-06-18 28 views
1

我試圖插入一些值到存儲在共享內存中的boost :: interprocess :: map。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 
] 

有沒有人有什麼想法?

+1

不確定它是否與你的問題有關,但是'map '的實際'value_type'是'pair ',而不是'pair '。即你的'Type_Value' typedef不正確。 – ildjarn

+0

感謝您的提示!不幸的是,這不是問題。 =) – George

回答

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鍵是常量,因此是插入對。你可能會更好使用std::string作爲關鍵。

+0

非常感謝!這就是訣竅!使用std :: string解決了它。 – George