Return Type in Function Overloading

suggest change

Note 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents