O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Virtual Constructors and Destructors

virtual is never used for constructors, but it is always a good idea for destructors. Otherwise, the superclass destructor may be called when a derived class is being destroyed through a superclass pointer or reference (by delete, in other words), and any storage allocated from the heap (or other resources claimed by the derived class) may not be disposed of properly. The fact that aTape's destructor is virtual ensures that its descendants will be disposed of safely. Since “virtuality” is inherited, aPersistentTape has a virtual destructor courtesy of aTape.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required