advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Partners & Affiliates
advertisement
advertisement
advertisement
Average Rating: 3.5/5 | Rate this item | 6 users have rated this item.
 

Use Function Adapters to Extend Generic Algorithms' Usage

Binding a member function to an object or a pointer can be done with the standard set of function adapters. Learn how in this month's solution.  


advertisement
As useful as pointers to member functions are, in certain situations—for example when using STL algorithms—you need to use more sophisticated constructs that wrap bare pointers to members and transform them into a slightly different beast.


STL algorithms that take a function argument don't care whether it's a real function, a member function, or a function object, so long as they can use the notation f() to call it. The problem is that you can't call a member function directly; you need to call it for a pointer or an object:


(p->*pmf)();  //invoke through a pointer
(obj.*pmf)(); //invoke through an object
How is it possible, then, to pass only a pointer to a member and have the algorithm call it?


Use the standard set of function adapters to bind a member function to an object or a pointer.

  Next Page: Step 1: Demonstrating the Problem
Page 1: IntroductionPage 3: Step 2: Using for_each()
Page 2: Step 1: Demonstrating the ProblemPage 4: Further Adaptation
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