1
我試圖創建一個使用this答案的內存映射文件,但我得到編譯錯誤。這是我的代碼:C++:Boost進程間內存映射文件錯誤
namespace bi = boost::interprocess;
std::string vecFile = "vector.dat";
bi::managed_mapped_file file_vec(bi::open_or_create,vecFile.c_str(), sizeof(struct Rectangle) * data_size);
typedef bi::allocator<struct Rectangle, bi::managed_mapped_file::segment_manager> rect_alloc;
typedef std::vector<struct Rectangle, rect_alloc> MyVec;
MyVec * vecptr = file_vec.find_or_construct<MyVec>("myvector")(file_vec.get_segment_manager());
vecptr->push_back(random_rectangle);
的結構是這樣的:
struct Rectangle{
Rectangle(float *minArr, float *maxArr, int arr, int exp, int ID){
this->arrival = arr;
this->expiry = exp;
this->id = ID;
for(int i=0; i < 2; i++){
min[i] = minArr[i];
max[i] = maxArr[i];
}
int arrival, expiry, id;
float min[2];
float max[2];
}
我得到的錯誤是:編譯器無法推斷出模板參數從「升壓::進程間「_Ty *」 :: offset_ptr」。我究竟做錯了什麼?
在不需要的情況下使用原始指針和'struct Rectangle'指示C編程風格。看到我的答案几個現代化。然而,更重要的是如何創建一個[SSCCE](http://sscce.org)。 – sehe