Effective C + +-----clause 12: Don't forget every ingredient when copying an object

Source: Internet
Author: User

The copying function should ensure that all member variables within the object and all base class components are copied.

Do not attempt to implement another copying function with one of the copying functions. Common functions should be put into the third function and called together by two coping functions. If you find that your copy constructor and the copy assignment operator have similar code, the practice of eliminating duplicate code is to create a new member function to call both. Such functions are often private and often named Init. This strategy can safely eliminate code duplication between the copy constructor and the copy assignment operator.

Effective C + +-----clause 12: Don't forget every ingredient when copying an object

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.