C++ boost::interprocess::map insert对重载函数的调用不明确

C++ boost::interprocess::map insert对重载函数的调用不明确,c++,boost,boost-interprocess,C++,Boost,Boost Interprocess,我正在尝试将一些值插入存储在共享内存中的boost::interprocess::map中 问题是,当我试图编译它时,它给了我“对重载函数的模糊调用”,我不知道为什么。以下是一些代码片段: #include <boost/interprocess/containers/map.hpp> #include <boost/interprocess/allocators/allocator.hpp> #include <boost/interprocess/managed

我正在尝试将一些值插入存储在共享内存中的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) );
#包括
#包括
#包括
typedef char*keype;
typedef长值类型;
typedef std::对类型_值;
typedef boost::进程间::分配器ShmemAllocator;
typedef boost::进程间::映射MyMap;
...
MyMap*MyMap=segment.construct(“CyValoresRTD”)//对象名
(std::less()//第一个参数
,alloc_inst)//第二个系数
...
char*text=“一些文本”;
长值=1234;
myMap->insert(std::make_pair(文本、值));
此insert调用给了我一些错误:

vcrtdserverimpl.cpp(445):错误C2668:'boost::进程间容器::map::insert':对重载函数的调用不明确
具有
[
Key=VCRTDServer::KeyType,
T=VCRTDServer::ValueType,
Pred=std::less,
Alloc=VCRTDServer::ShmemAllocator
]
p:\lib\boost\u 1\u 39\u 0\boost\interprocess\containers\container\map.hpp(407):可以是“std::pair boost::interprocess\u container::map::insert(const std::pair&)”
具有
[
_Ty1=boost::进程间容器::容器详细信息::rbtree::迭代器,
_Ty2=布尔,
Key=VCRTDServer::KeyType,
T=VCRTDServer::ValueType,
Pred=std::less,
Alloc=VCRTDServer::ShmemAllocator
]
p:\lib\boost\u 1\u 39\u 0\boost\interprocess\containers\container\map.hpp(396):或'std::pair boost::interprocess\u container::map::insert(const std::pair&)'
具有
[
_Ty1=boost::进程间容器::容器详细信息::rbtree::迭代器,
_Ty2=布尔,
Key=VCRTDServer::KeyType,
T=VCRTDServer::ValueType,
Pred=std::less,
Alloc=VCRTDServer::ShmemAllocator
]
尝试匹配参数列表“(std::pair)”时
具有
[
_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
            ]
可能是。。。
::插入(const std::pair&)'
或
::插入(const std::pair&)'
尝试匹配参数列表“(std::pair)”时
具有
[
_Ty1=char*,
_Ty2=int
]

std::map
键是常量,插入的对也是常量。您最好使用
std::string
作为键

错误消息会告诉您问题所在

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
            ]
可能是。。。
::插入(const std::pair&)'
或
::插入(const std::pair&)'
尝试匹配参数列表“(std::pair)”时
具有
[
_Ty1=char*,
_Ty2=int
]

std::map
键是常量,插入的对也是常量。您最好使用
std::string
作为键

不确定是否与您的问题有关,但
映射的真正
值类型
,而不是
。也就是说,您的
Type_值
typedef不正确。谢谢您的提示!不幸的是,这不是问题所在。=)不确定是否与您的问题有关,但
映射的真正
值类型
,而不是
。也就是说,您的
Type_值
typedef不正确。谢谢您的提示!不幸的是,这不是问题所在。=)谢谢!成功了!使用std::string解决了这个问题。非常感谢!成功了!使用std::string解决了这个问题。