rule-of-zero

Why does destructor disable generation of implicit move methods?

♀尐吖头ヾ 提交于 2019-12-17 15:56:10
问题 I was trying to understand what the rule of zero says by reading this blog. IMO, it says if you declare your own destructor then don't forget to make the move constructor and move assignment as default. Example: class Widget { public: ~Widget(); // temporary destructor ... // no copy or move functions }; "The addition of the destructor has the side effect of disabling generation of the move functions, but because Widget is copyable, all the code that used to generate moves will now generate

Rule of Zero confusion?

拥有回忆 提交于 2019-12-01 01:46:16
问题 So I have been reading about the Rule of Zero. Simplified version: I do not understand the purpose of this rule. The rule of three and five are sort of "rule of thumbs", but I cannot see the "rule of thumb" or any other specific intentions with this rule. Detailed version: Let me quote: Classes that have custom destructors, copy/move constructors or copy/move assignment operators should deal exclusively with ownership. Other classes should not have custom destructors, copy/move constructors

Why does destructor disable generation of implicit move methods?

不打扰是莪最后的温柔 提交于 2019-11-27 20:39:26
I was trying to understand what the rule of zero says by reading this blog . IMO, it says if you declare your own destructor then don't forget to make the move constructor and move assignment as default. Example : class Widget { public: ~Widget(); // temporary destructor ... // no copy or move functions }; "The addition of the destructor has the side effect of disabling generation of the move functions, but because Widget is copyable, all the code that used to generate moves will now generate copies. In other words, adding a destructor to the class has caused presumably-efficient moves to be