← Quiz: Copy Constructor and Deep Copy: all 10 questions
Quiz: Copy Constructor and Deep Copy · Question 4 of 10
Why is a shallow copy dangerous for a class whose destructor does delete[] data?
Why is a shallow copy dangerous for a class whose destructor does delete[] data?
- A.It uses too much memory
- B.It is slower than a deep copy
- C.Both objects delete the same array when destroyed — a double delete
- D.The destructor is never called
Answer & explanation
Correct answer: Both objects delete the same array when destroyed — a double delete
Two owners of one block means two deletes, which is undefined behaviour.
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 →