Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Simplify Callback Dispatching with Enumerated Indexes

Using callbacks instead of direct function calls is a must in event-based applications. This usefulness also extends to other application domains, where they can really make your life easier—that is, until you need to know which pointer is bound to which function and you realize you've forgotten! This month's solution explains how you can use enum types to avoid getting lost in your array of callback pointers.


advertisement
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.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap