+ 1
Rearrange the code to declare a template function "greater", taking two arguments and returning the greater one. Arguments are o
2 Respuestas
+ 1
template<typename T>
T greater(T a, T b) {
if(a > b)
return a;
return b;
}
And you use it like this:
int y = greater<int>(5,4); //y is 5
char a = 'a', b = 'b';
char c = greater<char>(a, b); //c is 'b'
0
Rearrange the code to declare a template function "greater", taking two arguments and returning the greater one. Arguments are of template types T and U, respectively.
Answer:
template <class T, class U>
T greater(T a, U b) {
if (a > b) {
return a; }
return b;
}