So what’s the problem?
before we had a pointer to “child” here, now we have a pointer to the parent class
So what happened to the destructor? How can that be?
Answer: A flaw in the “badparent” class implementation -- it does not define a destructor, so the compiler, who refers to the “child” by the pointer to the parent, never knew that there is a destructor to call.
#endif /* __BADPARENT_H__ */
will convert the bad into a good parent class.
A side note: When I had job interviews with several software companies in Germany, on two occasions I was given this problem to prove that I knew my C++.