TONGARI writes:
I hate to continue this, I've been working with this a bit more and am running
into another compilation issue that is vague to me. I am now trying to put the
object Complex_Data into a vector in shared memory below and it is complaining
about the following:
error C2679: binary '=' : no operator found which takes a right-hand operand of
type 'const complex_data' (or there is no acceptable conversion)
1> c:\code\test.cpp(113):
Line 133 is the end of the complex data class (closing bracket) It seems that it
is expecting the class to have an assignment operator or copy constructor, I am
not sure. I appreciate any help you might have. I am kind of trying to follow
the container of container example but instead using a vector.
#include
#include
#include
#include
#include
using namespace boost::interprocess;
using std::cout;
using std::endl;
//Typedefs of allocators and containers
typedef managed_shared_memory::segment_manager segment_manager_t;
typedef allocator void_allocator;
typedef allocator int_allocator;
typedef vector int_vector;
typedef allocatorint_vector_allocator;
typedef vectorint_vector_vector;
typedef allocator char_allocator;
typedef basic_string char_string;
typedef allocator char_string_allocator;
typedef vectorchar_string_vector_vector;
typedef char_string_vector_vector::iterator char_string_vector_iterator;
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 simplify
//the initialization taking just one allocator for all inner containers.
complex_data(int id, const char *name, double prce, const void_allocator
&void_alloc): id_(id), char_string_(name, void_alloc),
char_string_vector_vector_(void_alloc), price_(prce)
{}
void addStringItem(const char* s)
{
//Every time you build from a raw string you need an allocator
//in the constructor
char_allocator alloc(char_string_vector_vector_.get_allocator());
char_string_vector_vector_.push_back(char_string(s, alloc));
}
};
typedef allocator ShmemExchangeDataAllocator;
typedef vector ComplexDataVector;
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 type
void_allocator alloc_inst(segment.get_segment_manager());
ComplexDataVector* myComplexDataVector =
segment.construct<ComplexDataVector>("ComplexDataVector")(alloc_inst);
complex_data myItem(7, "hi", 7.0, alloc_inst);
myItem.addStringItem("hello");
myItem.addStringItem("how");
myItem.addStringItem("are");
myItem.addStringItem("you");
myComplexDataVector->push_back(myItem);
//
return 0;
}