Hello
I'm having a bit of trouble with something and I was hoping someone would be able to help me out. I'm using boost interprocess.
Here's what I have:
class Animal
{
... code removed...
}
class Dog : public Animal
{
... code removed...
}
class Cat : public Animal
{
... code removed...
}
typedef boost::interprocess::allocator, managed_shared_memory::segment_manager> ShmemAllocator;
typedef vector, ShmemAllocator> MyVector;
int main(int argc, char * const argv[]) {
..code removed..
managed_shared_memory segment(create_only, "MySharedMemory", 65536);
const ShmemAllocator alloc_inst(segment.get_segment_manager());
MyVector *myVector = segment.construct<MyVector>("MyVector")(alloc_inst);
intrusive_ptr dogPtr(segment.construct<Dog>("DogPtr")());
myVector->push_back(dogPtr);
The myVector->push_back(dogPtr) line gives the following error:
error: no matching function for call to 'boost::container::vector, boost::interprocess::allocator, boost::interprocess::segment_manager, boost::interprocess::iset_index> > >::push_back(boost::interprocess::intrusive_ptr&)'
I have been unable to get this to work. Can someone please tell me how to get my dogPtr into my Animal array?
I was able to get it to work like this:
intrusive_ptr animalPtr(dynamic_pointer_cast<Animal>(dogPtr.get()));
myVector->push_back(animalPtr);
But that's kind of ugly, creating a new variable and all. I'm hoping I don't have to do that.
Many thanks