- The Takeaway
- Document Management
- The Base Class: AnyOldDocument
- Economy in Coding
- The First Document Type: A Memo
- The Second Document Typean Invoice
- The Third and Last Document Typea Contract
- Leveraging Base Class Generality
- Polymorphism
- Complete Program Output
- Make Your Destructors Virtual
- Conclusion
- Additional Reading
Make Your Destructors Virtual
As we saw earlier, making destructors virtual is a terrific way of ensuring that resource deallocation can occur. This is a feature of C++ that comes for free and is well worth using as a matter of course. Virtual destructors are automatically invoked, so there’s no big effort required on the programmer’s part. However, do remember that virtual functions aren’t as efficient as their nonvirtual counterparts. So, if performance is a key requirement, you might like to carefully consider the use of virtual functions.