【发布时间】:2014-06-30 07:46:09
【问题描述】:
我在boost::managed_shared_memory 中实现boost::circular_buffer。我使用了在共享内存here 中演示向量的示例代码。我做了以下更改:
1) typedef boost::circular_buffer<int, ShmemAllocatorCB> MyCircularBuffer;
2) MyCircularBuffer *circbuff = segment.construct<MyCircularBuffer>("MyCB")(alloc_inst);
3) circbuff->push_back(1);
代码在第 3 行出现编译错误。错误是
error C2665: 'operator new' : none of the 5 overloads could convert all the argument types c:\boost2005\boost\circular_buffer\base.hpp 1470
从documentation,我了解到 push_back 函数需要以下三种形式之一:
void push_back(param_value_type);
void push_back(rvalue_type);
void push_back();
我尝试了空参数调用,尝试将 1 转换为 param_value_type、rvalue_type 但它们似乎都不起作用。这可能是一个简单的错误,但我已经有一段时间无法弄清楚了。任何帮助表示赞赏。谢谢。
编辑:
typedef allocator<int, managed_shared_memory::segment_manager> ShmemAllocatorCB;
managed_shared_memory segment(create_only, "MySharedMemory", 65536);
const ShmemAllocatorCB alloc_inst (segment.get_segment_manager());
【问题讨论】:
-
嗯,问题似乎是构造对象而不是推动它。如果您在 push_back 调用中发表评论,我怀疑该错误将持续存在。我认为您需要详细说明。特别是:
ShmemAllocatorCB是如何定义的,alloc_inst是什么? -
@hfhc2 :请检查编辑。该错误是在 push_back() 调用中准确引入的。如果我把它注释掉,程序编译就好了。
标签: c++ boost circular-buffer