1. When will the default move constructor be automatically generated?
If you need to use an rvalue to copy-construct a class object or assign a value to a class object, if the class has a customized move constructor/move assignment function, the class's customized move constructor/move assignment will be called. function
In the absence of a custom move constructor/move assignment function, if the class customizes one of the copy constructor/assignment operator or destructor, only the copy constructor/assignment operator will be called (provided that The formal parameter is const T& instead of T&, because const T& can be compatible with rvalue arguments, but T& cannot) and a default move constructor will not be generated. Note that even if there is no custom copy constructor/assignment operator and only a custom destructor, a default move constructor will not be generated. This is because the custom destructor indicates that the class may need to reclaim memory when it is destructed. If a default move constructor is generated, an error may occur (such as an error where the same address is released twice)
- No copy constructor declared
- No assignment operator declared
- No destructor declared
2. When will the default move assignment be automatically generated?
- No copy assignment function declared.
- No copy constructor declared.
- No move constructor declared.
- Move assignment functions are not implicitly declared delete.
- No destructor declared.