C ++ standard library study notes-notes for auto_ptr

Source: Internet
Author: User

There are four points in the book, as shown below:

1. You cannot share ownership between auto_ptrs.

This is easy to understand. Two auto_ptrs have the same object. If one of them deletes the object at a certain time point, the other naturally becomes a wild pointer, and then it is used for read/write memory, the consequences will be very serious.

2. There is no auto_ptrs designed for array.

The reason is very simple, because the auto_ptr source code uses Delete instead of Delete [] to release the memory of all objects.

3. auto_ptrs is not a "universal" smart pointer

Because auto_ptr is not a smart pointer based on reference counting technology.

4. auto_ptrs does not meet the requirements of STL containers for its elements

This is also easy to understand, because for this intelligent pointer that is not very useful, her copy and assign semantics will make you feel uncomfortable, because it involves a question of ownership transfer. therefore, please do not use her as an element of the standard container.

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.