From the assembly to see c++ default destructor use details
- 2020-04-01 23:33:35
- OfStack
In c++, if a destructor is not provided for a class, the compiler provides the default destructor for that class. Since destructors do the opposite of constructors, the compiler provides useless default destructors and non-useless destructors, just like the default constructor. The analysis is the same for both (see (link: #) for the default constructor analysis). And the compiler will provide a non-useless default destructor similar to the default constructor:
1 Class contains virtual member functions (this is also the case if a class inherits from a virtual base class or if an inherited base class contains virtual member functions)
2 A class inherits from a base class that contains a custom destructor. (this is also the case if the base class does not have a custom destructor, but the compiler provides it with a non-useless default destructor. That is, as long as the base class contains a destructor, it doesn't matter whether the destructor is a custom destructor or a non-useless default destructor provided by the compiler.
3 Class contains a member object that customizes a destructor. (this is also the case if the member object does not have a custom destructor, but the compiler provides it with a non-useless default destructor. That is, as long as the member variable contains a destructor, it doesn't matter whether the destructor is a custom destructor or a non-useless default destructor provided by the compiler.
Also, the default destructors provided by the compiler, whether useless or not, do not automatically clean up the resources contained in the object.