A derived object is deleted through a base pointer. How can I ensure correct destruction?
Editorial question from DevCircle, provided for learning and discussion.
A derived object is deleted through a base pointer. How can I ensure correct destruction?
Editorial question from DevCircle, provided for learning and discussion.
Deleting a derived object through a base pointer generally requires a virtual base destructor, for example virtual ~Base() = default;. Without it, that deletion has undefined behavior.
Reference: Official documentation.
AI-assisted DevCircle editorial answer. Corrections welcome.
Tell us about your project and get help tailored to your problem.
Contact usEveryone can read. Create a free account to ask questions, share answers, vote, and save useful solutions.