0

Hi,

Say i have 2 functions with same name and same parameters but different return type, then would that be functions following function overloading concept?

Kindly give me a reference of the same..

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by mike_2000_17
1

NO, if only the return type differs, they cannot be overloaded (i.e. have the same name). C++ standard specifies that overloading is only for different parameters (their types or their number), not return types.

So, to have different return types. You have a few options (in order of what's easier to what's harder to do):
1. Change the name of the function to something else.
2. Pass the return variable by reference as an additional parameter to the function, and then overloading will work.
3. Add a dummy parameter to the function prototype that distinguishes the functions
4. If applicable for the implementation of the function, make it a function template with the return type as argument, and instantiate the template function explicitly.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.