【问题标题】:boost::interprocess::map insert gives: ambiguous call to overloaded functionboost::interprocess::map insert 给出:对重载函数的模糊调用
【发布时间】:2012-06-18 21:07:53
【问题描述】:

我正在尝试将一些值插入到存储在共享内存中的 boost::interprocess::map 中。

问题是当我尝试编译它时它给了我“对重载函数的模棱两可的调用”,我不知道为什么。下面是一些sn-ps的代码:

#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
]

有人有什么想法吗?

【问题讨论】:

  • 不确定是否与您的问题有关,但map&lt;char*, long&gt; 的真正value_typepair&lt;char* const, long&gt;,而不是pair&lt;char const*, long&gt;。 IE。你的Type_Value typedef 不正确。
  • 感谢您的提示!不幸的是,这不是问题。 =)

标签: c++ boost boost-interprocess


【解决方案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 作为密钥可能会更好。

【讨论】:

  • 非常感谢!那成功了!使用 std::string 解决了它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-11
  • 2011-12-12
  • 2014-09-05
  • 2016-03-26
  • 1970-01-01
相关资源
最近更新 更多