MCQ Hive stays free thanks to ads. Please disable your ad blocker for this site so content and features keep working.
Fundamental Programming
Object-Oriented Concepts
Beginner
Q
Why must a C++ copy constructor take its parameter by reference, as in X(const X&)?
AOnly for const-correctness
BBecause constructors cannot take value parameters
CReferences are faster
DPassing by value would require calling the copy constructor itself, causing infinite recursion
Correct Answer:
D. Passing by value would require calling the copy constructor itself, causing infinite recursion
Explanation:
A by-value parameter needs a copy, which needs the copy constructor, and so on. The standard makes X(X) ill-formed.
ALSO KNOW (related points):
β’ Which statement about a static data member of a C++ class is correct? β A single copy is shared by all objects of the class