c++ - boost::interprocess::map 插入给出:对重载函数的模糊调用

标签 c++ boost boost-interprocess

我正在尝试将一些值插入存储在共享内存中的 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
]

有没有人有什么想法?

最佳答案

错误信息告诉你问题所在。

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 作为键。

关于c++ - boost::interprocess::map 插入给出:对重载函数的模糊调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11091061/

相关文章:

c++ - 如何让 gdb 从 icc "CHKP: Bounds check error"中断 `-check-pointers=write`

c++ - 了解链表中的 cdr 和 car 差异

c++ - Boost.Python dll 在编译时被跳过

c++ - c++11 中是否有 shared_memory_object 的替代品

c++ - Boost Interprocess named_mutex 导致段错误

c++ - 在进程之间共享类指针

c++ - C++ 中的 Gnome N 元树用法

c++ - 如何检查一个函数是否被另一个函数调用?

c++ - Boost graph typedef c++ 结构的前向声明

c++ - unordered_multimap<string, string> 到 map<string, string> 软搜索,如何做这样的事情以及如何预处理 map 以加快搜索速度?