Question 17
Back to Exercise
A class holds std::unique_ptr<Impl> where Impl is only forward-declared in the header. Why must the destructor be defined in the .cpp file?
- A Destructors are always in .cpp files
- B unique_ptr needs the complete Impl type to delete it, and Impl is complete only in the .cpp file Correct
- C To make it virtual
- D It doesn't matter
Correct Answer: Option B
An implicitly generated (inline) destructor in the header would try to delete an incomplete type and fail to compile.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!