Original Post
Hey, I need to write some kind of handle class for objects in my game such that when the object is destroyed and freed, the handle no longer points to invalid memory. My idea was to use something like the Observer pattern, and make a Publisher base class that has a list of handles that reference it. Then I could extend this class in any class in my game (such as a physical entity), and when the destructor is called, it would inform all of the handles of its destruction. This wouldn't work because destructors arn't inherited. To fix it I would have to manually make sure each of the classes destructors calls a notify() method or something in the base class. Not a very elegant solution IMO. Any ideas to solve this or better patterns you can suggest? Thanks.