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,
Printable View
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,:D
C++ has a feature called auto-conversion of types. If we equate a function output to an [B]int[/B] variable that actually returns a [B]float[/B] value, we all know that it automatically converts [B]float[/B] output to an [B]int[/B] and assigns it to the variable.
With this feature if we overload the functions with different return types, it creates ambiguity.:eek:
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.