fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. struct Lambda
  5. {
  6. int operator()(char a, float f)
  7. {
  8. std::cout << a << " " << f << std::endl;
  9. return 1;
  10. }
  11. };
  12.  
  13. void command(std::function<int(char, float)> func)
  14. {
  15. int ret = func('a', 3.14f);
  16. }
  17.  
  18. template <typename F>
  19. void tcommand(F func)
  20. {
  21. func();
  22. }
  23.  
  24. int main()
  25. {
  26. Lambda Obj;
  27. command(std::bind<int>(Obj, std::placeholders::_1, std::placeholders::_2));
  28. tcommand(std::bind<int>(Obj, 'b', 2.72f));
  29. }
  30.  
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
a 3.14
b 2.72