fork(5) download
  1. #include <functional>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. struct Foo
  6. {
  7. bool comp(const Foo& a)
  8. {
  9. std::cout << "a = " << a.s << std::endl;
  10. return a.s == s;
  11. }
  12.  
  13. std::string s;
  14.  
  15. };
  16.  
  17. struct Bar
  18. {
  19. int a;
  20. };
  21.  
  22.  
  23. template <class F, class T>
  24. void execute (F f, T a)
  25. {
  26. std::cout << "Result: " << f (a) << std::endl;
  27.  
  28. }
  29.  
  30. int main()
  31. {
  32. Foo* f1 = new Foo;
  33. f1->s = "Hello";
  34.  
  35. Foo f2;
  36. f2.s = "Bla";
  37.  
  38. Bar b;
  39. b.a = 100;
  40.  
  41. execute (std::bind2nd (std::mem_fun(&Foo::comp), b), f1);
  42.  
  43.  
  44. return 0;
  45. }
Runtime error #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty