fork(28) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int multiply(int x, int y)
  6. {
  7. return x * y;
  8. }
  9.  
  10. template <class F>
  11. void foo(int x, int y, F f)
  12. {
  13. cout << f(x, y) << endl;
  14. }
  15.  
  16. template <int (*F)(int,int)>
  17. void bar(int x, int y)
  18. {
  19. cout << F(x, y) << endl;
  20. }
  21.  
  22. int main()
  23. {
  24. foo(3, 4, multiply); // works
  25. bar<multiply>(3, 4); //now it works!
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 2680KB
stdin
Standard input is empty
stdout
12
12