+ 1

Rearrange the code to declare a template function "greater", taking two arguments and returning the greater one. Arguments are o

27th Feb 2017, 7:34 PM
saranya durairaj
saranya durairaj - avatar
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'
27th Feb 2017, 10:23 PM
Ettienne Gilbert
Ettienne Gilbert - avatar
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; }
23rd Sep 2020, 12:49 AM
OjeifoIduma