I have a class called Shape and a ShapeStorage class. The ShapeStorage class has a map ...
std::map<int, Shape*> shapes;
and function ...
Shape * ReturnShapePointer(int key) { Shape* shape = shapes[key]; shapes.erase(key); return shape; }
My goal is for my main class to instantiate a ShapeStorage object, save some shape * on the shape map. Then later I want to delete it from my card, but not delete it. I want my main class to still be able to access the value.
I tried to do this and my pointer still returns the correct values, but I'm afraid that since the destructor is called for Shape when I delete the pointer from my map, so this is just garbage of data at this point.
Is there any way around this?
source share