fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct foo
  5. {
  6. int min(int a, int b) { return a < b ? a : b; }
  7. int max(int a, int b) { return a > b ? a : b; }
  8. };
  9.  
  10. typedef int(foo::*function_type)(int, int);
  11.  
  12. void processor(function_type func, foo* object)
  13. {
  14. std::cout << "1 and 2 = " << (object->*func)(1, 2) << std::endl;
  15. std::cout << "5 and 2 = " << (object->*func)(5, 2) << std::endl << std::endl;
  16. }
  17.  
  18. int main()
  19. {
  20. foo f;
  21.  
  22. processor(&foo::min, &f);
  23. processor(&foo::max, &f);
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
1 and 2 = 1
5 and 2 = 2

1 and 2 = 2
5 and 2 = 5