fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. struct Foo {
  5. void print_sum(int n1, int n2)
  6. {
  7. std::cout << n1+n2 << '\n';
  8. }
  9. int data = 10;
  10. };
  11.  
  12. int main()
  13. {
  14. using namespace std::placeholders; //for _1, _2, _3...
  15.  
  16. // bind to a member function
  17. Foo foo;
  18. auto f3 = std::bind(&Foo::print_sum, &foo, 95, _1);
  19. f3(5);
  20. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
100