Boost logo

Boost Users :

Subject: [Boost-users] Boost Shared Memory Compilation Issue
From: Nathan Lewis (nathanlewissubscription_at_[hidden])
Date: 2011-07-19 19:55:55

What an great library!

I am trying to extend one of the shared memory examples but I am getting a
compilation error. Basically I have added a vector of char_strings to the
complex object and added a method to add a string to the vector. If anyone
would take a moment to give me suggestion for how to fix this issue or a
suggestion for how I should better add strings to this vector I would
appreciate your input.

The error is:
error C2664: 'void boost::container::vector<T,A>::push_back(const
boost::interprocess::rv<T> &)' : cannot convert parameter 1 from
'char_string *' to 'const boost::interprocess::rv<T> &'
with [T=char_string, A=char_allocator]
Reason: cannot convert from 'char_string *' to 'const
No constructor could take the source type, or constructor overload
resolution was ambiguous

The code is:
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/map.hpp>
#include <boost/interprocess/containers/vector.hpp>
#include <boost/interprocess/containers/string.hpp>

using namespace boost::interprocess;

//Typedefs of allocators and containers
typedef managed_shared_memory::segment_manager segment_manager_t;
typedef allocator<void, segment_manager_t>
typedef allocator<int, segment_manager_t>
typedef vector<int,
int_allocator> int_vector;
typedef allocator<int_vector, segment_manager_t>
typedef vector<int_vector, int_vector_allocator>
typedef allocator<char, segment_manager_t>
typedef basic_string<char, std::char_traits<char>, char_allocator>
typedef vector<char_string, char_allocator>

class complex_data
public: //Obviously making the variables of complex_data public isn't a good
idea I am just playing here for the moment
   int id_;
   char_string char_string_;
   char_string_vector_vector char_string_vector_vector_;
   double price_;
   //Since void_allocator is convertible to any other allocator<T>, we
   //the initialization taking just one allocator for all inner containers.
   complex_data(int id, const char *name, double prce, const void_allocator
      : id_(id), char_string_(name, void_alloc),
char_string_vector_vector_(void_alloc), price_(prce)

   // add a string --> Error is on the next line
   void addStringItem(char_string*

int main ()
   //Remove shared memory on construction and destruction
   struct shm_remove
      shm_remove() { shared_memory_object::remove("MySharedMemory"); }
      ~shm_remove(){ shared_memory_object::remove("MySharedMemory"); }
   } remover;

   //Create shared memory
   managed_shared_memory segment(create_only,"MySharedMemory", 65536);

   //An allocator convertible to any allocator<T, segment_manager_t> type
   void_allocator alloc_inst (segment.get_segment_manager());

   //Construct the shared memory map and fill it
   complex_data *mymap = segment.construct<complex_data>("Complex_Data")(7,
"hi", 7.0, alloc_inst);

   return 0;

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at