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