← Quiz: Copy Constructor and Deep Copy: all 10 questions
Quiz: Copy Constructor and Deep Copy · Question 5 of 10
Why must the copy constructor take its parameter by reference?
Why must the copy constructor take its parameter by reference?
- A.References are faster to type
- B.Passing by value would itself need a copy, calling the copy constructor endlessly
- C.Because constructors cannot take values
- D.So the original can be changed
Answer & explanation
Correct answer: Passing by value would itself need a copy, calling the copy constructor endlessly
The compiler rejects T(T other) for this reason; use const T &.
Can you get the rest right without peeking?
Take the timed Quiz: Copy Constructor and Deep Copy quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →