fork(1) download
  1. #include <cstdio>
  2. #include <functional>
  3. template<class T>
  4. void test(T t, std::function<void(T)> f) { f(t); }
  5. //void test(T t, std::function<void(int)> f) { f(t); }
  6.  
  7. void PrintIt(int v){ printf("V=%d\n", v); };
  8.  
  9.  
  10. int main(int argc, char *argv[]) {
  11. test(5, PrintIt);
  12. }
  13.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main(int, char**)':
prog.cpp:11:20: error: no matching function for call to 'test(int, void (&)(int))'
     test(5, PrintIt);
                    ^
prog.cpp:11:20: note: candidate is:
prog.cpp:4:6: note: template<class T> void test(T, std::function<void(T)>)
 void test(T t, std::function<void(T)> f) { f(t); }
      ^
prog.cpp:4:6: note:   template argument deduction/substitution failed:
prog.cpp:11:20: note:   mismatched types 'std::function<void(T)>' and 'void (*)(int)'
     test(5, PrintIt);
                    ^
stdout
Standard output is empty