Difficulty: Easy
Correct Answer: Only one
Explanation:
Introduction / Context:
Although constructors may be overloaded, the notion of a “default constructor” is specific: it is a constructor callable with no arguments. This question explores how many such default constructors a class can define according to C++ rules and overload resolution constraints.
Given Data / Assumptions:
Concept / Approach:
A class can have only one default constructor. You may have many constructors, but at most one of them can be viable with zero arguments. Having more than one would either be the same signature (redefinition error) or lead to ambiguity when invoked with no arguments. You can implement a single default constructor directly or by using default arguments to make one of the parameterized constructors callable with no arguments, but still there is only one effective default constructor in the set.
Step-by-Step Solution:
Verification / Alternative check:
Try compiling a class with two constructors both invocable as T(). The compiler emits an error (duplicate definition or ambiguous call). Refactor so that exactly one is default-constructible, and the code compiles and runs.
Why Other Options Are Wrong:
Two/Three/Unlimited: contradict signature uniqueness and overload resolution rules.
Common Pitfalls:
Final Answer:
Only one
Discussion & Comments