The Destructor is a reverse constructor. They are called when objects are withdrawn (recycled. Except for the "~" at the beginning, Symbol, which is the same as the class name. For example, the destructor of the String class is ~ String (). Destructor are usually used to complete the "elimination" function when an object is no longer needed.
After an object is created in the function, the object starts to survive as a local object until the function runs until it meets the right brace "}". At this time, the Destructor is called.
The release of objects occurs in the following situations:
· Objects allocated using the new operator are deleted by delete.
· A local (automatic) object with block scope is out of its scope.
· The lifetime of the temporary object ends.
· The program stops running.
· Display the destructor of the called object with a fully qualified name.
Several Rules constrain the description of the Destructor:
· Parameters are unacceptable.
· It cannot indicate that there are any return types (including void ).
· Return values cannot be returned using the return statement.
· Const, volatile, or static functions cannot be described, but destructor can be called for the analysis of const, volatile, or static objects.
· Virtual. Using a virtual destructor, you can undo an object without having to know its type. Because of the virtual function mechanism, the program will call the correct destructor of this object.
Http://blog.csdn.net/chenlinben/article/details/8002471
This article is from the "chenlinben" blog, please be sure to keep this source http://linben.blog.51cto.com/6205951/1293488