0

I always assumed that the compiler will automatically generate copy constructors and copy operators in C++ if one is not specified. Is this also the case for move constructor/move operator?

In other words, do we need to specify a move constructor and move operator to get benefits of move semantics. OR are they provided by the compiler by default?

I was reading some articles recently that state that sometimes move semantics will break if there is a custom destructor declared in a class.

When does it make sense to actually write a move constructor/move operator?

Grapes
  • 2,473
  • 3
  • 26
  • 42
  • see this link? http://stackoverflow.com/questions/4819936/why-no-default-move-assignment-move-constructor – taocp Apr 05 '13 at 13:45
  • 1
    We don't provide default constructors. They are default. (yeah, that doesn't make sense) – Bartek Banachewicz Apr 05 '13 at 13:46
  • @tacp So if a destructor is specified, I have to write both move operator and move constructor for all classes? – Grapes Apr 05 '13 at 13:49
  • @Grapes: according to answer in that post: if X does not have a user-declared destructor, then implicit move constructor will be declared. If you have your own destructor, then I guess you have to write your own move constructor since implicit version will not be generated. – taocp Apr 05 '13 at 13:53
  • @BartekBanachewicz: We often provide default constructors. It's implicit constructors that we don't provide. – Mike Seymour Apr 05 '13 at 14:24

0 Answers0