我正在尝试在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)
答案 0 :(得分: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>