0
我有下面的代碼,它寫結構來提升共享內存。我無法添加新的float *或Vector。升壓版本:1.59.0獲得一堆錯誤作爲Float *或向量在Boost共享結構
error: no matching function for call to ‘boost::interprocess::allocator<boost::container::container_detail::list_node<float, boost::interprocess::offset_ptr<void>......."
嘗試:
typedef boost::interprocess::list<float, salloc::rebind<float>::other> shared_float;
任何建議如何添加浮子*或將被添加來提高共享存儲器結構矢量
#include <iostream>
#include <string>
#include <cstdlib>
#include <boost/interprocess/ipc/message_queue.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/string.hpp>
#include <boost/interprocess/containers/vector.hpp>
#include <boost/shared_array.hpp>
#include <boost/interprocess/containers/list.hpp>
#include <boost/version.hpp>
using namespace boost::interprocess;
struct InData;
typedef boost::interprocess::allocator<InData, managed_shared_memory::segment_manager> salloc;
typedef boost::interprocess::basic_string<char, std::char_traits<char>, salloc::rebind<char>::other> shared_string;
struct InData {
int X, Y, H, W;
InData(salloc alloc) : Label(alloc) {}
shared_string Label;
};
int main() {
std::cout << "Using Boost "
<< BOOST_VERSION/100000 << "." // major version
<< BOOST_VERSION/100 % 1000 << "." // minor version
<< BOOST_VERSION % 100 // patch level
<< std::endl;
shared_memory_object::remove("MySharedMemory");
managed_shared_memory managed_shm(create_only, "MySharedMemory", 10000);
salloc alloc_inst(managed_shm.get_segment_manager());
InData tData(alloc_inst); // = managed_shm.construct<InData>("InDataStructure")();
tData.Label = "Hello World";
tData.H = 1;
tData.W = 1;
tData.Y = 1;
tData.X = 1;
typedef boost::interprocess::list<InData, salloc> MyList;
MyList *myvector = managed_shm.construct<MyList>("MyVector")(alloc_inst);
myvector->push_back(tData);
}
不能簡寫的錯誤。該錯誤說「錯誤:沒有匹配的函數調用X」,你設法把比「X」有趣的一半, – sehe