Run a Destructor with ofAddListener

Why can’t I do that?

ofAddListener(in->deleteEvent, this, &Connection::~Connection);  

The error is:

src/Connection.cpp|12|error: taking address of destructor ‘ds::Connection::~Connection’|  

For now I’m calling another method which simply runs

delete this;  

in it.

Is there a better way to do that? Why I can’t pass the Destructor to ofAddListener?

Thanks for your help.


the listener for an event must have the following signature;

if the event is:

ofEvent<Type> event  

the method must be:

void method(Type & parameter)  

so you can’t pass the destructor to the event. Also it seems kind of weird to try to do that, if you need to destroy an object when something happens probably you want to register a class that contains the ones you want to destroy and register a method of that class with a certain parameter that tells it which object needs to be destroyed

thanks, will try that!