Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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.




Application Security Testing: An Integral Part of DevOps

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.

Comment and Contribute






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



Thanks for your registration, follow us on our social networks to keep up-to-date