Return Type in Function Overloading
suggest changeNote that you cannot overload a function based on its return type. For example:
// WRONG CODE
std::string getValue()
{
return "hello";
}
int getValue()
{
return 0;
}
int x = getValue();
This is ill-formed. Two functions that differ only by return type are not overloads, so the second getValue is a conflicting declaration. The initialization of x never selects a function by its return type.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents