Function overloading: which statement is correct under standard C++ rules? Assume normal overload resolution; default arguments do not change a function’s signature.

Difficulty: Easy

Correct Answer: A function can be overloaded more than once.

Explanation:


Introduction / Context:
Overloading allows multiple functions to share a name while differing in their parameter lists. This enables more intuitive APIs when operations conceptually share a name but work on different types or arities.


Given Data / Assumptions:

  • Signatures differ by parameter count and/or types and/or cv/ref qualifiers.
  • Default arguments do not participate in the function type and do not distinguish overloaded functions.
  • We are not considering templates here, only ordinary overloading.


Concept / Approach:
A program may provide more than two overloads of the same function name—“overloaded more than once”—as long as each overload has a distinct signature. By contrast, two functions that have identical parameter lists cannot be overloaded regardless of whether they use default arguments. Default arguments influence call sites but not the function's type identity.


Step-by-Step Solution:
1) Legal: void f(int); void f(double); void f(int, int); // three overloads2) Illegal: void f(int); and again void f(int); // identical signatures3) Irrelevant: adding/removing defaults does not fix identical signatures.4) Therefore, the correct statement is that a function can be overloaded multiple times.


Verification / Alternative check:
Create several overloads with unique parameter lists and compile; then attempt two identical ones (with or without defaults) and observe a redefinition error.



Why Other Options Are Wrong:
Same number/order/type: cannot be overloaded; defaults do not help.“Must have default arguments”: untrue; defaults are optional and unrelated to overloading.“Defaults starting from left”: ordering rule is trailing-from-the-right, and defaults are not required for overloading.



Common Pitfalls:
Mixing defaults with overloads in headers and sources inconsistently, causing ambiguous calls; prefer to specify defaults once in a single declaration.



Final Answer:
A function can be overloaded more than once.

More Questions from Functions

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion