fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. using namespace std;
  5.  
  6. struct A
  7. {
  8. void f() const { cout << this << ", A::f()" << endl; }
  9. void g() const { cout << this << ", A::g()" << endl; }
  10. void h() const { cout << this << ", A::h()" << endl; }
  11. };
  12.  
  13. int main()
  14. {
  15. A a;
  16. auto f = function<void(A&)>{&A::f};
  17. auto g = bind(&A::g, &a);
  18. auto h = [&a](){ a.h(); };
  19.  
  20. function<void()> func;
  21.  
  22. cout << "Uzycie: " << endl;
  23. f(a);
  24. g();
  25. h();
  26.  
  27. cout << "std::function: " << endl;
  28. func = g;
  29. func();
  30. func = h;
  31. func();
  32.  
  33. }
  34.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
Uzycie: 
0xbfbf5f9f, A::f()
0xbfbf5f9f, A::g()
0xbfbf5f9f, A::h()
std::function: 
0xbfbf5f9f, A::g()
0xbfbf5f9f, A::h()