Why we can not do overloading on the basis of return type? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Why we can not do overloading on the basis of return type?

answer: The time when metohd is called, it can not decide which one to b executed. Coz syntax for calling them will be same, whether it is return type or void.So it leads to ambiguity.

2nd Apr 2017, 6:09 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
2 Answers
+ 8
I already knew it. Still you deserve a like. ;)
2nd Apr 2017, 6:13 PM
Cyrus Ornob Corraya
Cyrus Ornob Corraya - avatar
+ 3
It should be noted that the only reason this leads to ambiguity is because you can call functions without making use of the return type. That's the key point here. If this possibility didn't exist (and we didn't have implicit conversions) it would be perfectly reasonable to expect the compiler to pick a function based on context.
2nd Apr 2017, 8:00 PM
Squidy
Squidy - avatar