fork download
  1. #include <functional>
  2. #include <iostream>
  3.  
  4. struct A
  5. {
  6. int foo(int a)
  7. {
  8. return a;
  9. }
  10. };
  11.  
  12. class B
  13. {
  14. private:
  15. std::function<int(int)> pfoo;
  16. public:
  17. B(std::function<int(int)> foofunc)
  18. : pfoo(foofunc) { }
  19. int cFoo(int i)
  20. {
  21. return pfoo(i);
  22. }
  23. };
  24.  
  25. int main()
  26. {
  27. A my_a;
  28. B my_b(std::bind(&A::foo, my_a, std::placeholders::_1));
  29. std::cout << my_b.cFoo(2);
  30. return 0;
  31. }
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
2