In C++, when the compiler cannot distinguish between two overloaded constructors (or functions) based on their parameter lists, the overload set is said to be what?

Difficulty: Easy

Correct Answer: ambiguous

Explanation:


Introduction / Context:
Function and constructor overloading lets you reuse names for different parameter lists. However, if a call could match more than one candidate with no clear best conversion sequence, the compiler cannot pick uniquely. Recognizing the term for this situation helps diagnose compile-time errors and fix API design issues.


Given Data / Assumptions:

  • Multiple overloads share the same name.
  • A call site provides arguments whose types/conversions make more than one overload viable.
  • No single overload is strictly better according to C++ overload resolution rules.


Concept / Approach:

  • When no unique best match exists, overload resolution fails with an ambiguous call.
  • Ambiguity can arise from implicit conversions, default arguments, or templated overloads.
  • Eliminating ambiguity involves making the call explicit (casts), removing conflicting overloads, or adding more specific overloads.


Step-by-Step Solution:

Identify the scenario: two or more viable constructors match equally well.Apply the rule: if no single best conversion sequence exists, the call is ambiguous.Therefore, the correct term is ”ambiguous”.


Verification / Alternative check:

Try compiling code where int converts to both long and double with similar ranks; compilers emit an ”ambiguous” overload resolution error.


Why Other Options Are Wrong:

  • overloaded: Describes the existence of multiple functions, not the failure mode.
  • destructed / dubious: Not standard terminology in this context.
  • None of the above: Incorrect because ”ambiguous” is the precise diagnostic term.


Common Pitfalls:

  • Relying on implicit conversions that create ambiguity; prefer explicit interfaces.
  • Overusing default parameters that collide with other overloads.


Final Answer:

ambiguous

Discussion & Comments

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