0

我正在尝试在 VS 2010 中构建一段代码,该代码通常在网上找到,作为在共享内存中拥有地图的示例。

#include <boost\interprocess\managed_shared_memory.hpp>
#include <boost\interprocess\containers\map.hpp>

typedef boost::interprocess::map<long,long,
            std::less<long>,
            boost::interprocess::allocator<std::pair<long,long>,
                boost::interprocess::managed_shared_memory::segment_manager> >
        shmap;

boost::interprocess::managed_shared_memory segment1(
    boost::interprocess::create_only, 
    "MySharedMemory", 655360); //segment name and size in bytes

shmap *rp = segment1.construct<shmap>("SharedMap")(
    std::less<long>(), segment1.get_segment_manager());

我得到了这个让我大吃一惊的错误。有任何想法吗?

error C2338: (container_detail::is_same<std::pair<const Key, T>, typename A::value_type>::value)
4

1 回答 1

2

应该

typedef boost::interprocess::map
<long,long,std::less<long>,
boost::interprocess::allocator<std::pair<const long,long>, 
boost::interprocess::managed_shared_memory::segment_manager> > shmap;

由于内部检查是is_same<std::pair<const Key, T>, Allocator::value_type>

于 2012-09-15T14:21:50.630 回答