I need to define an event handler and then to add it to an array of handlers at a certain index. The handler will never be called by its real name, so I want to handle both the definition and the assignment in one place. A good solution would look like this:
MAKE_HANDLER(evet_code, my_event) {
//handle the event
}
My naive solution was to have this expand into
void on_my_event(event* ev);
array_of_handlers[event_code] = &on_my_event;
void on_my_event(event* ev) {
//handle the event
}
Obviously this doesn't work, since an assignment cannot occur in global scope (except for initialization by constant). I am aware that I could have one macro define the function and another assign it in main, however this would be a duplication of information and very tedious to work with, when I have many handlers. What other solutions are there?