Which of the following is not true for overloaded functions C++?
2013
Which of the following is not true for overloaded functions C++?
Answer: B. Overloaded functions having the same argument lists should have a different return type. — Correct answer: The statement "Overloaded functions having the same argument lists should have a different return type." is not true. Explanation: Function…
- A.
Overloaded functions should have different argument lists.
- B.
Overloaded functions having the same argument lists should have a different return type.
- C.
Functions cannot be overloaded on the basis of one being static and the other non-static.
- D.
None of these
Attempted by 337 students.
Show answer & explanation
Correct answer: B
Correct answer: The statement "Overloaded functions having the same argument lists should have a different return type." is not true.
Explanation:
Function overloading is determined by the function signature, which includes the function name and the parameter list (number of parameters, types, and their order).
The return type is not part of the signature used for overload resolution, so you cannot overload solely by changing the return type. Example of an invalid pair: int func(int); and double func(int); — this is a redefinition error because the parameter lists are identical.
The static specifier is not part of the function signature either, so you cannot overload only by making one function static and the other non-static.
Note: const qualification for member functions is part of the signature and can be used to overload member functions (for example, void f(); and void f() const; are distinct).
Therefore, the incorrect statement is the one claiming return-type-only overloading is allowed; the correct rule is that overloaded functions must differ in their parameter lists.