class apple { public: ~apple(){ std::cout << "~apple()" << std::endl;} }; class banana : public apple { ~banana(){ std::cout << "~banana()" << std::endl;} }; class cat { virtual ~cat(){ std::cout << "~cat()" << std::endl;} }; class dog : public cat { ~dog(){ std::cout << "~dog" << std::endl;} }; int main(void) { banana* pa1 = new banana; delete pa1; banana* pa2 = new banana; delete (apple*)pa2; dog* pd1 = new dog; delete pd1; dog* pd2 = new dog; delete (cat*)dog; }