Memory management and std::vector.erase()

I'm trying to use std::vector to hold a 'PhysObj' class to be used in physical simulation.

My visible objects in the scene have a 'PhysObj' member pointer, and when they are created, this pointer is added to the vector with std::vector.push_back()

I'm not sure how to handle this if the death of the object is decided outside the physical simulation. It seems impossible for each object in the scene to know their position in the std::vector in order to call .erase() on themselves (would that even be possible?)

The simple case is how to erase 'emitted' type particles which are set to be removed after a time interval? Could they co-exist with other objects that have more arbitrary creation or deletion criterea? Does all the extra members need to be included as some inherited class from my base PhysObj class?

I think that my simulation must call .erase() on the member before the parent Class calls its destructor. I haven't used destructors before and I'm not sure how they function to manage memory. I have seen basic diagrams of how bytes are stored in memory but a good exhaustive reference with graphical representation would be helpful.

Any links or suggestions would be appreciated.
Thanks.
Topic archived. No new replies allowed.