Listing 7
#include <functional> #include <iostream> using std::cout; using std::tr1::mem_fn; struct S { // struct with two member functions void show() const { cout << "S::show\n"; } void show_int(int i) const { cout << "S::show_int(" << i << ")\n"; } }; int main() { // demonstrate use of mem_fn S s; S *sp = &s; s.show(); // call member function on an object sp->show_int(3); // call member function on an object mem_fn(&S::show)(s); // call through wrapper on an object mem_fn(&S::show_int)(sp, 3); // call through wrapper on an object return 0; }