Difficulty: Easy
Correct Answer: All arguments of an overloaded function can be default.
Explanation:
Introduction / Context:
Overloading and default arguments interact. While both features are legal together, careless combinations can create ambiguous calls. The language itself does not forbid defaults on overloads; it only requires that declarations be consistent and unambiguous at call sites.
Given Data / Assumptions:
Concept / Approach:
All parameters of a particular overload can be defaulted, making that overload callable with zero explicit arguments. There is no “at most one default” restriction in the standard. Claims that overloads cannot have defaults are false; many real-world APIs mix both. The key is to ensure that different declarations do not lead to ambiguous calls, especially when some overloads have defaults and others do not.
Step-by-Step Solution:
1) Legal example: void f(int a = 1, int b = 2); // callable as f(), f(3), f(3,4)2) Coexist with overload: void f(double); // distinct signature3) Avoid ambiguous pairs like void f(int); and void f(int a = 0); within the same scope.4) Conclusion: It is correct that all arguments of an overloaded function can be defaulted.
Verification / Alternative check:
Compile a set of overloads where one has fully defaulted parameters and another has a clearly different signature; calls resolve correctly.
Why Other Options Are Wrong:
“At most one default”: false; multiple defaults are allowed.“Cannot have default”: false; perfectly legal.“Overloaded more than once cannot have default”: also false.
Common Pitfalls:
Specifying defaults for the same parameter in multiple declarations or crafting overload sets where omitted arguments cause ambiguity.
Final Answer:
All arguments of an overloaded function can be default.
Discussion & Comments