fork download
  1. #include <functional>
  2. #include <iostream>
  3.  
  4. void foo(double arg){
  5. std::cout << "foo, argument = " << arg << "\n";
  6. }
  7.  
  8. struct foo_functor{
  9. void operator()(float arg) const{
  10. std::cout << "foo_functor, argument = " << arg << "\n";
  11. }
  12. };
  13.  
  14. int main(){
  15. std::function<void(int)> f1(foo), f2((foo_functor()));
  16. f1(5);
  17. f2(6);
  18. f1(4.7);
  19. }
  20.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
foo, argument = 5
foo_functor, argument = 6
foo, argument = 4