Functions and usage of destructor

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.