Which of the following constructors can be provided implicitly by the C++…
2023
Which of the following constructors can be provided implicitly by the C++ compiler if they are not defined in a class?
- A.
Copy constructor
- B.
Default constructor
- C.
Parameterized constructor
- D.
More than one of the above
- E.
None of the above
Attempted by 158 students.
Show answer & explanation
Correct answer: D
Correct answer: More than one of the above.
Default constructor: If a class has no user-declared constructor, the compiler implicitly declares a default constructor.
Copy constructor: If a class has no user-declared copy constructor, the compiler also implicitly declares a copy constructor, although it may be defined only when it is needed and may be deleted in some special cases.
Parameterized constructor: The compiler does not invent a user-style parameterized constructor. It must be written explicitly.
Therefore, both the default constructor and the copy constructor can be compiler-provided, so the best option is More than one of the above.