fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. template<class T>
  6. T f(T x, T y) {
  7. return x < y ? x : y;
  8. }
  9.  
  10. int main() {
  11. {
  12. double x = (double)5;
  13. cout << x << endl;
  14. }
  15. {
  16. double x = f(1.5, 3);
  17. cout << x << endl;
  18. }
  19. return 0;
  20. }
Compilation error #stdin compilation error #stdout 0s 4268KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:16:21: error: no matching function for call to ‘f(double, int)’
  double x = f(1.5, 3);
                     ^
prog.cpp:6:3: note: candidate: ‘template<class T> T f(T, T)’
 T f(T x, T y) {
   ^
prog.cpp:6:3: note:   template argument deduction/substitution failed:
prog.cpp:16:21: note:   deduced conflicting types for parameter ‘T’ (‘double’ and ‘int’)
  double x = f(1.5, 3);
                     ^
stdout
Standard output is empty