In C++, what happens when two overloaded functions have the same number and types of parameters but differ in return type?

  • It's a compilation error
  • It's undefined behavior
  • The function with the least specific return type is called
  • The function with the most specific return type is called
When two overloaded functions in C++ have the same number and types of parameters but differ in return type, it results in a compilation error. C++ uses the function's signature, including the return type, to differentiate between overloaded functions. If two functions have the same parameters and differ only in return type, it becomes ambiguous, and the compiler cannot determine which function to call.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *