Hello forum!
I have a event-listener-system.
Example: A window tells the caller-system (who stores listeners and tells whether an event has been triggered) it wants to start listening.
If the caller receives the information of a triggered event, it will notify all listeners to that specific event.
Every listener derives from a handler-class for each event they want to listen to.
class Window_Changer : public Event_Handler<Click_Event>
Here is what a window-class calls to register itself:
click_event_listener(event_bus.Add_handler<Click_Event>(*this))
My caller statically casts the this-pointer to a void-pointer that can be stored.
Later, when the listened event has been triggered, I static cast the void-pointer to a Event_Handler<T> and later cast it to what T is.
I really want to get away from this C-style of using void-pointers though.
Assuming std::function would be a good direction, I'm still a bit rusty in terms of using it.
How could I turn my object into a std::function instead of a void-pointer?
To be more precise:
// call from the listener
click_event_listener(event_bus.Add_handler<Click_Event>(*this))
// happening in the Add_handler-method
static_cast<void*>(&object)
Are there certain things to be aware of?
Can I static_cast back from that to a generic Event_Handler<T>, as I did above?
Thanks for taking your time : )