C + + Detail series (0): Fragmented records

Source: Internet
Author: User

The usual: Record the details, wait for the spare, and then organize.

1:const,static,const static member initialization.

1. Const member: can only be initialized in the initialization list after the constructor

2. Static member: Initialization is outside the class and does not add static adornments.

3. const STATIC MEMBER: The class has only one copy, and the value cannot be changed. Therefore, it can be initialized in a class, or it can be initialized outside of the class like static.

2: Copy assignment function and copy constructor.

1, copy the assignment function.

1) The return value is a reference to the left type.

2, copy constructor.

1, the usual principal function should be: Copy all non-static class members.

2, the system is constructed by default. But try to do it yourself (unless the class copy is simple).

3, the parameter must be a reference. Doing so will result in recursive calls and eventually crashes.

3, copy assignment functions and copy constructors are required by each other. That is, if you need to define a copy assignment function, you must define a copy constructor. Vice versa.

3:explicit keyword.

1, the constructor that identifies this keyword must be displayed for use. cannot be called implicitly.

4: destructor.

1, the destructor function body does not carry out the destruction of class members. Instead, the member is destroyed when the destructor body is complete.

2, for pointers, the destroy function destroys the pointer itself only, and does not destroy the object pointed to by the pointer. Therefore, you need to delete/free the pointer in the destructor

3, in principle, a class has a destructor, it should also have its own copy constructor and copy assignment function.

5: Move function.

1, it is divided into moving function and moving assignment function.

2, move function (including assignment) feature: "Stealing" the data of the source object. Causes the source object to enter an unpredictable situation.

3, the use of mobile functions will improve the efficiency of operation. It should be noted, however, that if the object after "stealing" data is still referenced by other threads and functions, it can cause unpredictable errors.

C + + Detail series (0): Fragmented records

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.