C++核心準(zhǔn)則C.63:保證移動(dòng)賦值運(yùn)算符為非虛函數(shù),參數(shù)類型為右值...

C.63:保證移動(dòng)賦值運(yùn)算符為非虛函數(shù),參數(shù)類型為右值引用,返回值為常量引用類型
It is simple and efficient.
這樣做簡(jiǎn)單且高效。
The rule for copy-assignment.
拷貝賦值規(guī)則。
相關(guān)鏈接:
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rc-copy-assignment
Equivalent to what is done for copy-assignment.
和拷貝賦值的情況時(shí)所做的相同。
(Simple) An assignment operator should not be virtual. Here be dragons!
(簡(jiǎn)單)賦值運(yùn)算符不應(yīng)該是虛函數(shù)。那樣做很危險(xiǎn)。
(Simple) An assignment operator should return T& to enable chaining, not alternatives like const T& which interfere with composability and putting objects in containers.
(簡(jiǎn)單)賦值運(yùn)算符應(yīng)該返回T&,這樣才能實(shí)現(xiàn)連續(xù)賦值。不要改成類似const T&的類型,這樣會(huì)影響組裝性并妨礙將對(duì)象放進(jìn)容器中。
(Moderate) A move assignment operator should (implicitly or explicitly) invoke all base and member move assignment operators.
(中等)移動(dòng)賦值運(yùn)算符應(yīng)該(隱式或顯式)調(diào)用所有的基類和成員的移動(dòng)賦值運(yùn)算符。
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c63-make-move-assignment-non-virtual-take-the-parameter-by--and-return-by-non-const-
覺得本文有幫助?請(qǐng)分享給更多人。
關(guān)注【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!
面向?qū)ο箝_發(fā),面向?qū)ο笏伎迹?/span>
