Hello For simplicity, say I have this: class Animal { int id; }; class Dog : public Animal { int tag; }; class Cat : public Animal { int lives; }; offset_ptr<Dog> a = segment.construct<Dog>(anonymous_instance)(); offset_ptr<Animal> b; b = a; Also assume I have a correctly setup managed_shared_memory called segment. Is there anyway I can delete the constructed object using b? I tried segment.destroy_ptr(b.get()) and segment.deallocate(b.get()) but I get assertion failures. Obviously segment.destroy_ptr(a.get()) would work but I'd like to be able to do it with a pointer to the parent class. Also casting won't work because I won't know if it's a dog or a cat when I delete it. Thanks for any suggestions!
El 07/10/2011 2:15, Brian escribió:
Is there anyway I can delete the constructed object using b? I tried segment.destroy_ptr(b.get()) and segment.deallocate(b.get()) but I get assertion failures. Obviously segment.destroy_ptr(a.get()) would work but I'd like to be able to do it with a pointer to the parent class. Also casting won't work because I won't know if it's a dog or a cat when I delete it.
No, you need virtual destructors for that, and classes with virtual operations are not safely placeable in shared memory. Best, Ion
participants (2)
-
Brian
-
Ion Gaztañaga