C ++ copy control operation (three / five law)

When you define a class, we explicitly or implicitly specifies the object of this type of copying, assignment and what to do when destroyed. Controlled by a class member functions defined in these three special operations are copy constructor , copy assignment operator and destructor .

Copy constructor defines what to do when initializing the new object with another object of the same type, copy assignment operator defines what to do when an object is given the same type of another object, the object is defined destructor destruction of this type what to do when. These operations will be referred to the copy control operation .

Because the copy operation is controlled by the three special member functions to complete, so we call this the "C ++ Three Laws." In the newer C ++ 11 standard, in order to support the move semantics, increased mobile constructor and move assignment operator , so there are five special member functions, it is also known as "C ++ five law." In other words, the "three rule" is for the older C ++ 89 standard says, "five law" is for the newer C ++ 11 standard say. In order to unify call, then people call it dry "C ++ three / five rule."

to sum up:

1. destructors need to be copied and also class assignment

2. The need also need to copy operation class assignment, and vice versa

3. Whether copy constructor needs or need to copy assignment operator need not necessarily implies destructor

Guess you like

Origin www.cnblogs.com/xiaobaizzz/p/12356412.html