can I change the T with whatever I want like?? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

can I change the T with whatever I want like??

template <class numb, class Y> numb greater(numb a, Y b) { return (a > b ? a : b); } int main() { int x = 10; int y = 20; cout << greater(x,y) << endl; return 0; } //this code gonna work right??

11th Dec 2016, 3:16 PM
Fluffy Rabbit
Fluffy Rabbit - avatar
2 Réponses
+ 3
Yes it will work. But some cases if first parameter is int and second parameter is string undefined behaviour will happen in your conditional operator statement. Apart from you can use anything instead of T.
11th Dec 2016, 3:58 PM
Venkatesh(Venki)
Venkatesh(Venki) - avatar
0
OK thanks a lot
11th Dec 2016, 4:00 PM
Fluffy Rabbit
Fluffy Rabbit - avatar