Hello all,
Why cant we overload a function with return type in C++?
We know that compiler wont support, but is there any specific reason for it?
Thanks,
Hello all,
Why cant we overload a function with return type in C++?
We know that compiler wont support, but is there any specific reason for it?
Thanks,
Overloading can be done by various signatures of a function.
return type is not the signature.
I agree with Barbie.
One more reason that comes in my mind is,
C++ has a feature called auto-conversion of types. If we equate a function output to an int variable that actually returns a float value, we all know that it automatically converts float output to an int and assigns it to the variable.
With this feature if we overload the functions with different return types, it creates ambiguity.
Lack of WILL POWER has caused more failure than
lack of INTELLIGENCE or ABILITY.
-sutnarcha-
Thanks dude..
Ur answer made my doubt clear
C++ mangles the function name in the object file (after it is compiled) with the function's parameter types but not the return type. Therefore, the linker cannot distinguish between functions with the same parameter types but different return types since the object module lacks the information so do that.