Can't we use simply one template to check whether the number is greater? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can't we use simply one template to check whether the number is greater?

https://code.sololearn.com/cJmipOK3afuM/?ref=app

31st Oct 2020, 12:02 PM
Harshit Nema
Harshit Nema - avatar
6 Answers
+ 11
Harshit Nema , this is far too less information in your post. Please rework your question so that we clearly understand what problem you have. Also put the programming language in tag. Thanks!
31st Oct 2020, 12:05 PM
Lothar
Lothar - avatar
+ 3
Harshit Nema If we only use T then both argument must be of the same type, as I understand.
31st Oct 2020, 12:22 PM
Ipang
+ 1
Lothar now you can see it
31st Oct 2020, 12:11 PM
Harshit Nema
Harshit Nema - avatar
+ 1
"Can't we use simply one template..." Yes, but that function compares an int and a double. That's why two template class were used. You can use just one template class if you are sure the two function parameters' type were of the same data type.
1st Nov 2020, 8:22 AM
Ipang
+ 1
int and double are fundamentally different types. Two different template generics makes the function possible for two different types or two parameters of the same type. It's just as Ipang said, if you want the function to be defined for only one type, then use one template, else if you want it be defined for different types, you have to have two templates.
1st Nov 2020, 3:44 PM
Donato Paul Thayalan
Donato Paul Thayalan - avatar
0
Yes that's my point.
1st Nov 2020, 7:59 AM
Harshit Nema
Harshit Nema - avatar