fork download
  1. #include <functional>
  2. #include <iostream>
  3.  
  4. struct Foo {
  5. Foo(int num) : num_(num) {}
  6. void print_add(int i) const { std::cout << num_+i << '\n'; }
  7. int num_;
  8. };
  9.  
  10.  
  11. int main()
  12. {
  13. // store a call to a member function
  14. std::function<void(const Foo&, int)> f_add_display = &Foo::print_add;
  15. const Foo foo(314159);
  16. f_add_display(foo, 1);
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
314160