Guest User

Untitled

a guest
Jan 13th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <functional>
  2. #include <stdio.h>
  3.  
  4. struct Test1 {
  5. int n;
  6. Test1(int n) : n(n) {}
  7. void show() {
  8. printf("%d\n", n);
  9. }
  10. };
  11.  
  12. struct Test2 {
  13. int n;
  14. Test2(int n) : n(n) {}
  15. void show() {
  16. printf("%d\n", n);
  17. }
  18. };
  19.  
  20. struct Test3 {
  21. static void show() {
  22. printf("?\n");
  23. }
  24. };
  25.  
  26. void show() {
  27. printf("!\n");
  28. }
  29.  
  30. void call(const std::function<void()> &f) {
  31. f();
  32. }
  33.  
  34. int main() {
  35. Test1 t1(1);
  36. Test2 t2(2);
  37. auto f1 = std::bind(&Test1::show, &t1);
  38. auto f2 = [&t2] { t2.show(); };
  39. auto f3 = Test3::show;
  40. auto f4 = show;
  41. call(f1);
  42. call(f2);
  43. call(f3);
  44. call(f4);
  45. }
Add Comment
Please, Sign In to add comment