fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //template<typename T> T f(T x = T() ) { return x; }
  5.  
  6. template<typename T> T f( T x) { return x; }
  7.  
  8. template<typename T> T f()
  9. {
  10. return f<T>(T());
  11. }
  12.  
  13. int main() {
  14.  
  15. auto a = f();
  16. std::cout << a;
  17. return 0;
  18. }
  19.  
Compilation error #stdin compilation error #stdout 0s 3412KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:15:13: error: no matching function for call to 'f()'
  auto a = f();
             ^
prog.cpp:6:24: note: candidate: template<class T> T f(T)
 template<typename T> T f( T x) { return x; }
                        ^
prog.cpp:6:24: note:   template argument deduction/substitution failed:
prog.cpp:15:13: note:   candidate expects 1 argument, 0 provided
  auto a = f();
             ^
prog.cpp:8:24: note: candidate: template<class T> T f()
 template<typename T> T f()
                        ^
prog.cpp:8:24: note:   template argument deduction/substitution failed:
prog.cpp:15:13: note:   couldn't deduce template parameter 'T'
  auto a = f();
             ^
stdout
Standard output is empty