fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. void Print(int v)
  7. {
  8. cout << v << endl;
  9. }
  10.  
  11. void Print(double v)
  12. {
  13. cout << v << endl;
  14. }
  15.  
  16. template<typename FnT>
  17. void Function(int v, FnT&& fn)
  18. {
  19. fn(v);
  20. }
  21.  
  22. int main() {
  23.  
  24. Function(1, Print);
  25.  
  26. vector<int> v = { 1,2,3 };
  27. for_each(v.begin(), v.end(), Print);
  28.  
  29. return 0;
  30. }
Compilation error #stdin compilation error #stdout 0s 16064KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:24:22: error: no matching function for call to ‘Function(int, <unresolved overloaded function type>)’
     Function(1, Print);
                      ^
prog.cpp:17:6: note: candidate: template<class FnT> void Function(int, FnT&&)
 void Function(int v, FnT&& fn)
      ^~~~~~~~
prog.cpp:17:6: note:   template argument deduction/substitution failed:
prog.cpp:24:22: note:   couldn't deduce template parameter ‘FnT’
     Function(1, Print);
                      ^
prog.cpp:27:39: error: no matching function for call to ‘for_each(std::vector<int>::iterator, std::vector<int>::iterator, <unresolved overloaded function type>)’
     for_each(v.begin(), v.end(), Print);
                                       ^
In file included from /usr/include/c++/6/algorithm:62:0,
                 from prog.cpp:2:
/usr/include/c++/6/bits/stl_algo.h:3763:5: note: candidate: template<class _IIter, class _Funct> _Funct std::for_each(_IIter, _IIter, _Funct)
     for_each(_InputIterator __first, _InputIterator __last, _Function __f)
     ^~~~~~~~
/usr/include/c++/6/bits/stl_algo.h:3763:5: note:   template argument deduction/substitution failed:
prog.cpp:27:39: note:   couldn't deduce template parameter ‘_Funct’
     for_each(v.begin(), v.end(), Print);
                                       ^
stdout
Standard output is empty