Explicitly defaulted move constructor

前端 未结 2 2074
广开言路
广开言路 2020-12-18 00:28

According to the c++11 standard a default move constructor is only generated if:

  • X does not have a user-declared copy constructor, and
  • X does not have
相关标签:
2条回答
  • 2020-12-18 01:18

    Yes, you can always explicitly invoke the default generation for functions that can be automatically generated with = default. That's what the syntax is for.

    0 讨论(0)
  • 2020-12-18 01:29

    The motivation for that rule is that if the default copy constructor doesn't work for your class, then chances are the default move constructor won't work either (rule of 5, or whatever we're up to in C++11). So yes, you can explicitly default it, on your honor as a programmer that it'll work.

    In your example code you could instead remove the copy constructor, since it does the same as the default.

    0 讨论(0)
提交回复
热议问题