I have a class called SpriteX which basically is a generic sprite. I also have a class called _Drawables which has a member std::vector<SpriteX*>. In main() every sprite I create can be inserted into the _Drawables container and then can call the drawAll() method to draw all the SpriteX objects in the std::vector.
Each SpriteX object has knows which index the pointer to itself is located, and in its destructor, it sets the pointer to NULL. But I want to completely destroy the pointer, not just set it to NULL. But is deleting the pointer safe? If I use delete in the destructor, and that calls the destructor, would that cause a loop? Is there any way to release the memory.
Yes, that will probably result in a stack overflow and a crash.
But you don’t need to do that, since if you’re in the destructor, you’re already deleting the memory, right? (as in, you’re not explicitly calling the destructor I hope)