fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. struct T
  5. {
  6. T(int x) : x(x) {};
  7. void foo() { std::cout << x; }
  8.  
  9. private:
  10. int x;
  11. };
  12.  
  13. int main()
  14. {
  15. using namespace std::placeholders; //for _1, _2, _3...
  16. auto f = std::bind(&T::foo, _1);
  17.  
  18. T obj(5);
  19. f(obj); // Output: 5
  20. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
5