Callbacks, either in the form of function pointers
or pointers to members
, offer a significant advantage over direct function calls: the caller doesn't have to know a function's name (nor its object's name, if it's a member function) in order to invoke it. Alas, this anonymity is a fertile source of human errors as programmers might lose track of which pointer is bound to which function. This solution demonstrates a simple and effective technique to overcome this problem.
How to associate meaningful names to indexes of an array of callback pointers?
Use enum types to enumerate array indexes.