C ++ core principles C.63: assignment operator to ensure non-virtual mobile function, referred to as the right argument type value, the return value is a constant reference type

C.63: Move the Make non-Assignment Virtual, by && Take The Parameter, and return by non-const &
c.63: assignment operator to ensure non-virtual mobile function, referred to as the right argument type value, the return value is constant reference Types of

 

Reason (reason)

It is simple and efficient.

Simple and efficient to do so.

 

See (see):

The rule for copy-assignment.

Copy assignment rules.

 

Related Links:

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rc-copy-assignment

 

 

 

Enforcement (Suggestions)

Equivalent to what is done for copy-assignment.

And copy assignment of the same situation when done.

  • (Simple) An assignment operator should not be virtual. Here be dragons!

    (Simple) assignment operator should not be virtual. Do very dangerous.

  • (Simple) An assignment operator should return T& to enable chaining, not alternatives like const T& which interfere with composability and putting objects in containers.

    (Simple) assignment operator should return to T &, so as to achieve continuous assignment. Do not change the type const T & Similarly, it will affect and interfere with the assembly of the objects into the container.

  • (Moderate) A move assignment operator should (implicitly or explicitly) invoke all base and member move assignment operators.

    (Average) assignment operator should move (implicit or explicit) calls the base class and all the moving members of the assignment operator.

Description link

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c63-make-move-assignment-non-virtual-take-the-parameter-by--and-return-by-non-const-

 


 

I think this article helpful? Welcome thumbs up and share it with more people.

Read more updated articles, please pay attention to micro-channel public number of object-oriented thinking []

Published 408 original articles · won praise 653 · views 290 000 +

Guess you like

Origin blog.csdn.net/craftsman1970/article/details/104701336