05. Understand what functions C + + silently writes and calls
- Compile the resulting destructor when non-virtual, unless the base class destructor for this class is virtual
- Copy assignment function cannot be generated automatically when there are references and const members in member variables
- When the base class declares the copy assignment operator as private, the compiler refuses to generate a copy assignment operator for its derived classes.
06. If you do not want to use a function generated automatically by the compiler, you should explicitly deny
- Automatically generated default constructor, copy constructor, copy assignment declared as private
- Declaring private is not completely secure, and member functions and friend functions can be called--and declared, but not defined (resulting in link errors)
- Define a base class, default constructor, copy constructor, copy assignment declared as private, inherit from derived class (Generate compilation error, Noncopyable class in Boost)
07. Declaring the virtual destructor for a polymorphic base class
- When a base class pointer points to a derived class, the Delete base class pointer cannot be called to the destructor of the derived class
- Any class with the virtual function should have a virtual destructor.
- When class does not contain a virtual function, it usually means that it is not intended to be used as a base class.
- When class does not attempt to be treated as a base class, its destructor is often a bad idea for virtual. (Occupy space, reduce efficiency)
08. Don't let exceptions escape destructors
- When a destructor does not catch an exception, if the class object is stored in a container, an exception may cause other objects in the container to be unable to refactor.
- Destructors need to catch exceptions, some actions that throw exceptions can be moved out of the destructor and processed by a customer call
Effective C + +--tectonic-destructor assignment operation