【发布时间】:2015-05-28 17:57:54
【问题描述】:
编辑:虽然严格来说不是我正在寻找的答案,但那是因为我问错了问题。我已将此问题标记为“已回答”,因为它帮助我了解自己做错了什么(回到上下文中,类结构没有意义,需要使用类似的更改以不同方式重做),我认为海报值得修复他所说的“非标准”的代表提升。
请花时间帮助解决这个问题。如果你对 Boost 的经验比我多,那应该不难。
我正在使用 Boost 1.57 进行 IPC。我正在尝试制作pair(void *,struct)的共享映射。这是一个完整的程序(短)。您可以将其插入 MSVC(或更改 main() 声明并将其更改为常规 managed_shared_memory、GCC 或 Clang)。
代码可以在http://pastebin.com/caNNdztt找到语法高亮显示(虽然我忘了去掉代码中不存在的#define的一种用法,它被替换为0x30000000)
#include <iostream>
#include <boost/interprocess/mapped_region.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/managed_windows_shared_memory.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/map.hpp>
using namespace boost::interprocess;
typedef void* mem_managed_type; // GLE_GLOBAL is just void *, but changing it to int doesn't work
struct global_ptr_state; // This is just a POD struct, the definition doesn't matter
//typedef managed_shared_memory mem_manager_t;
typedef managed_windows_shared_memory mem_manager_t;
typedef std::pair<const mem_managed_type, global_ptr_state> global_state_pair;
typedef mem_manager_t::segment_manager segm_t;
typedef allocator< global_state_pair, segm_t > my_global_allocator;
typedef std::less<mem_managed_type> mem_managed_type_less;
typedef mem_manager_t::segment_manager segm_manager;
typedef map<const mem_managed_type, global_ptr_state, mem_managed_type_less, my_global_allocator> global_ptr_pair_map;
int _tmain(int argc, _TCHAR* argv[])
{
segm_manager *_segm_manager;
my_global_allocator *_allocatr;
global_ptr_pair_map *global_map;
mem_manager_t managed_pool;
managed_pool = mem_manager_t(create_only, "thisdoesntmatter", 65536, (void *)0x3C000000);
shared_memory_object _stator_share(open_only, "thisdoesntmattereither", read_write);
mapped_region _stator_region(_stator_share, read_write, 0, 0, (void *)0x30000000);
_segm_manager = managed_pool.get_segment_manager();
_allocatr = new my_global_allocator(_segm_manager);
// This line throws the error
global_map = new global_ptr_pair_map; // This line causes the compilation error
}
错误的简短版本是
1>c:\boost\include\boost-1_57\boost\container\map.hpp(493): error C2535: 'std::pair<boost::container::container_detail::iterator<boost::intrusive::tree_iterator<boost::intrusive::bhtraits<T,boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void,ptrdiff_t,size_t,0>,true>,normal_link,boost::intrusive::default_tag,3>,false>,false>,bool> boost::container::map<const mem_managed_type,global_ptr_state,mem_managed_type_less,my_global_allocator,boost::container::tree_assoc_defaults>::insert(const std::pair<const mem_managed_type,global_ptr_state> &)'
: member function already defined or declared
可以在 Pastebin 上找到整个错误
据我所知,它在抱怨这个:
std::pair<iterator,bool> insert(const nonconst_value_type& x)
{ return this->base_t::insert_unique(x); }
在该标题中替换上面的语句:
std::pair<iterator,bool> insert(const value_type& x)
{ return this->base_t::insert_unique(x); }
我无计可施。请帮忙!
【问题讨论】:
标签: c++ templates boost interprocess boost-interprocess