Home >Backend Development >C++ >How Do Automatic Move Operation Generation Rules Differ Between C 98 and C 11?
In C 98, the compiler could create copy constructors and copy assignment operators automatically through member-wise copy. This process extended to C 11 with the introduction of move semantics. However, the rules for automatic generation of move operations differ from those of copy operations.
Howard Hinnant's ACCU 2014 presentation provides a concise overview of these rules. The following table summarizes the key points:
</p> <table> <thead><tr> <th> </th> <th>Destructor</th> <th>Move Constructor</th> <th>Move Assignment Operator</th> </tr></thead> <tbody> <tr> <td>C 98/03</td> <td>No</td> <td>Yes</td> <td>Yes</td> </tr> <tr> <td>C 11 (Defect Report 1492)</td> <td>Yes</td> <td>No</td> <td>No</td> </tr> <tr> <td>C 11 Final</td> <td>Yes</td> <td>Yes<sup>*</sup> </td> <td>Yes<sup>*</sup> </td> </tr> </tbody> </table> <p>
Yes: Automatically generated.
No: Not automatically generated.
*But only implicitly defined (not declared or declared=default). Explicit definitions suppress generation.
These rules indicate that while move constructors and move assignment operators are generally generated automatically in C 11, there are some cases where they may not be. For instance, if the destructor is explicitly defined, the move operations will not be generated. Similarly, explicitly defining move operations themselves suppresses automatic generation.
The above is the detailed content of How Do Automatic Move Operation Generation Rules Differ Between C 98 and C 11?. For more information, please follow other related articles on the PHP Chinese website!