C + + Learning and Summary 1

Source: Internet
Author: User

1.shared_ptr

Analytical:

shared_ptr is a count pointer, and when the reference count becomes 0 o'clock, the object that shared_ptr points to will be deleted. For example, as follows:

1 voidTest () {2shared_ptr P1 (New int);//count is 13     {4shared_ptr P2 (p1);//Count is 25             {6shared_ptr P2 (p1);//Count is 37}//Count is 28}//count is 19}//The count is 0 while the Int object is deleted

2. Unique_ptr

Analytical:

Unique_ptr is a smart pointer (smart pointer) defined in <memory>. It holds the exclusive right to the object, that is, two unique_ptr cannot point to an object, and the copy operation can only be performed by a move operation.

Reference documents:

[1] cplusplus:http://www.cplusplus.com/

C + + Learning and Summary 1

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.