advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
The beauty in enum types is that they're both high-level and very efficient. Are you contented with the current syntactic and semantics specifications of enum types in C++ or would you like to add more functionality to them? (for examples of such added functionality see the following proposal for adding enum types to Java). Let us know in our C++ Discussion Forum.
Partners & Affiliates
advertisement
advertisement
advertisement
Average Rating: 3.3/5 | Rate this item | 8 users have rated this item.
 

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.

  Next Page: Demonstrating the Problem
Page 1: IntroductionPage 3: Enumerating Options
Page 2: Demonstrating the ProblemPage 4: enums Will Save the Day
Please rate this item (5=best)
 1  2  3  4  5
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs