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<intrusive_ptr<Animal, offset_ptr<Animal> >, managed_shared_memory::segment_manager> ShmemAllocator;
typedef vector<intrusive_ptr<Animal, offset_ptr<Animal> >, 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<Dog, offset_ptr<Dog> > 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::intrusive_ptr<Animal, boost::interprocess::offset_ptr<Animal> >, boost::interprocess::allocator<boost::interprocess::intrusive_ptr<Animal, boost::interprocess::offset_ptr<Animal> >, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> > >::push_back(boost::interprocess::intrusive_ptr<Dog, boost::interprocess::offset_ptr<Dog> >&)'
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<Animal, offset_ptr<Animal> > 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