A destructor is a class element that is called when a class goes out of scope. The class element that is called when a class is created is called the constructor.
- Design constructors, assignments, and the destructor as a matched set of operations [5]
- All base classes must have a (public) virtual destructor [1,3]
- A non-base class should have a (non-public) non-virtual destructor [1,3]
- Avoid calling virtual member functions in constructors and destructors [2]
- Don't call virtual member functions in constructors and destructors [9]
- Never let an exception escape from a destructor [4]
- If a constructor acquires a resource, its class needs a destructor to release the resource [6]
- If a class has a virtual member functions, it needs a virtual destructor [7,8]
- Generated destructors are implicitly noexcept [10,11]. Declaring a destructors noexcept explicitly is harmless and unconventional [11].
- Herb Sutter, Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. ISBN: 0-32-111358-6. Item 50: 'Make base class destructors public and virtual, or protected and nonvirtual'.
- Herb Sutter, Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. 2005. ISBN: 0-32-111358-6. Item 49: 'Avoid calling virtual functions in constructors and destructors'
- Joint Strike Fighter Air Vehicle C++ Coding Standards for the System Development and Demonstration Program. Document Number 2RDU00001 Rev C. December 2005. AV Rule 78: 'All base classes with a virtual function shall define a virtual destructor.'
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 13.7. Advice. page 387: '[30] Never let an exception escape from a destructor'
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 17.7. Advice. page 525: '[1] Design constructors, assignments, and the destructor as a matched set of operations'
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 17.7. Advice. page 525: '[3] If a constructor acquires a resource, its class needs a destructor to release the resource'
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 17.7. Advice. page 525: '[4] If a class has a virtual function, it needs a virtual destructor'
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 20.7. Advice. page 611: '[8] A class with a virtual function should have a virtual destructor'
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 22.7. Advice. page 663: '[7] Don't call virtual functions during construction and destruction'
- Bjarne Stroustrup's C++11 FAQ: 'A destructor shouldn't throw; a generated destructor is implicitly noexcept (independently of what code is in its body) if all of the members of its class have noexcept destructors.'
- Scott Meyers. Effective Modern C++ (1st Edition). 2014. ISBN: 978-1-491-90399-5. Item 14, page 94: 'By default, all memory deallocation functions and all destructors -both user-defined and compiler-generated- are implicitly noexcept. There is thus no need to declare them noexcept. (Doing so doesn't hurt anything, it's just unconventional.)'