May 2002
Beginner
320 pages
6h 18m
English
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.
Read now
Unlock full access