Objective C ++, 3rd edition, Chapter 2. Constructors (constructors), Destructors (destructor) and assignment operato

Source: Internet
Author: User

Chapter 2. constructors, Destructors, and assignment operators)

By Scott Meyers

Translator: fatalerror99 (itepub's nirvana)

Release: http://blog.csdn.net/fatalerror99/

Almost every class you write has one or more constructors, one destructor, and one copy assignment operator ). Don't be surprised. They are just like your bread. They control basic operations, such as creating a new object and ensuring that it has been initialized, eliminate an object and make sure it is completely cleared, and assign a new value to the object. Errors in these functions will cause your classes (classes) to have a profound impact and an unpleasant rebound, so ensuring they are correct is a matter of life and death. In this chapter, I will provide some guidance on how to assemble these functions as the hub backbone of a well-formed classes (Good class.

This chapter includes the following content. Click to open it:

  • Item 5: Know what functions C ++ silently writes and CILS
  • Item 6: Explicitly disallow the use of compiler-generated functions you do not want
  • Item 7: declare Destructors virtual in polymorphic base classes
  • Item 8: prevent exceptions from leaving Destructors
  • Item 9: Never call virtual functions during construction or destruction
  • Item 10: Have assignment operators return a reference to * This
  • Item 11: handle assignment to self in operator =
  • Item 12: Copy all parts of an object
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.