fork download
  1. #include <iostream>
  2.  
  3. void printer(float i){
  4. std::cout<<i<<std::endl;
  5. }
  6. //////////////////////////////////
  7. //template
  8. template<typename F,typename Arg>
  9. void Invoker(F func, Arg arg){
  10. func(arg);
  11. }
  12. /////////////////////////////////
  13.  
  14. /////////////////////////////////
  15. // function pointer
  16. typedef
  17. void // return type
  18. (*void_func_type) //this "type" name
  19. (float) //function args
  20. ;//end
  21. void Invoker1(void_func_type func, float arg){
  22. func(arg);
  23. }
  24. ////////////////////////////////
  25.  
  26. //functional
  27. #include <functional>
  28. void Invoker2(std::function<void(float)> func, float arg){
  29. func(arg);
  30. }
  31.  
  32.  
  33. int main(void) {
  34. // template
  35. Invoker(printer,10.f);
  36. // function pointer
  37. Invoker1(printer,10.f);
  38.  
  39. //functional
  40. Invoker2(printer,10.f);
  41.  
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
10
10
10