fork(7) download
  1. #include <iostream>
  2. #include <functional>
  3. using namespace std::placeholders;
  4.  
  5. int foo(int i)
  6. {
  7. return i*2;
  8. }
  9.  
  10. int main(int argc, const char *argv[])
  11. {
  12. std::function<int(int, int)> barfunc = std::bind(foo, (_1, _2));
  13. std::cout << barfunc(-999, 21) << std::endl;
  14.  
  15. // or even (thanks Xeo)
  16. barfunc = std::bind(foo, _2);
  17. std::cout << barfunc(-999, 21) << std::endl;
  18. }
  19.  
Success #stdin #stdout 0s 2960KB
stdin
Standard input is empty
stdout
42
42