Return type is not an basis of function overloading.
Overloading of functions can only be with one of the following criteria:
- No of arguments
- Type of arguments &
- Sequence of arguments
The return type can be ignored by the caller and hence it is not a valid criteria for function overloading.
Having said the above, pass by value and passing a Reference will create a ambiguity to the compiler. For eg:
void doSomething(int i)
{
}
void doSomething(int &i)
{
}
int main()
{
int val = 10;
doSomething(val); //Ambiguous
}
Here the compiler cannot determine as to pass val
to which version of doSomething()
. It can make a valid function call to any of the versions, so it cries out for help at compile time(since this is static linking) and flags the calls as ambiguous.
In case such as yours. It is a choice/preference as to rename the functions or pass pointer argument which will make the two functions overloaded(same name but different argument types). However, it is important to take in to account the requirement & the action the function is going to perform while choosing the preference. Personally, I wouldn't choose a pointer just for sake of overloading. If I do need to reseat or make my argument point to different variables then it would make sense to choose pointer argument.
Simple way is to just have two distinct function names. There is no overhead and it is just as efficient as any other function call.