destructor
- A destructor is used to destroy objects of its class type. The address of a destructor shall not be taken. A destructor can be invoked for a const, volatile or const volatile object.const and volatile semantics are not applied on an object under destruction. They stop being in effect when the destructor for the most derived object starts.
- A defaulted destructor for a class X is defined as deleted if:
- X is a union-like class that has a variant member with a non-trivial destructor
- any of the non-static data members has class type M (or array thereof) and M has a deleted destructor or a destructor that is inaccessible from the defaulted destructor
- any direct or virtual base class has a deleted destructor or a destructor that is inaccessible from the defaulted destructor
- or, for a virtual destructor, lookup of the non-array deallocation function results in an ambiguity or in a function that is deleted or inaccessible from the defaulted destructor.
- X is a union-like class that has a variant member with a non-trivial destructor
- A destructor is trivial if it is not user-provided and if:
- the destructor is not virtual,
- all of the direct base classes of its class have trivial destructors, and
- for all of the non-static data members of its class that are of class type (or array thereof), each such class has a trivial destructor.
- the destructor is not virtual,
- If a class has a base class with a virtual destructor, its destructor (whether user- or implicitly-declared) is virtual.
- destructor is implicitly invoked for constructed objects with thread storage duration at thread exit
- Note:
- During object construction (constructor), be very careful the objects referenced have been fully initialized.
- In constructor/destructor, pay close attention to calling "virtual function, dynamic_cast, typeid". They usually will NOT work as expected. So don't call these functions or operators in constructor/destructor.