+ 1
C++ - Templates - Where's the error?
Why doesn't this code function for "int" and "double"? #include <iostream> using namespace std; template <class T> T templating (T a, T b, T c){ T max = a; if(b > max){ max = b; } if(c > max){ max = c; } return max; }; int main() { cout << templating(1,4.7,3.9); return 0; }
1 Réponse
+ 5
All types are of type T so all arguments have to be of the same type. If you want to use different types you'd need to use something like
T templating(U a, V b, W c)