Notify on destruction

Hi,
I have a singleton factory object 'Manager' that create objects used by the 'user' which can destroy them.
Is there a way the 'Manager' will be notifyed when the created objects are destroyed?

Thanks,
Daniele.
you could use an observer pattern.

so your object has something like
1
2
3
4
5
6
class Foo {
    Manager listener;
  public:
    foo(Manager l) { this->listener = l;  }
    ~foo() { this->listener.notifyfunction(); }
};


im not sure if the syntax is correct this way, havent coded C++ for some time, but its more about the idea behind the pattern im trying to explain ;-)
That works, though you probably want to pass the manager by reference instead of by value.
Hi Mathes,

yes, in the beginning I thought to use the same pattern, but I would like if there was some "automatic" way without the necessity to modify created objects.
Or, for example, a sort of container that hold pointers to these objects and, when they are destroyed, it removes them automatically!

Thanks!
Daniele
Topic archived. No new replies allowed.