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?

5
  • see this link? stackoverflow.com/questions/4819936/… Commented Apr 5, 2013 at 13:45
  • 1
    We don't provide default constructors. They are default. (yeah, that doesn't make sense) Commented Apr 5, 2013 at 13:46
  • @tacp So if a destructor is specified, I have to write both move operator and move constructor for all classes? Commented Apr 5, 2013 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. Commented Apr 5, 2013 at 13:53
  • @BartekBanachewicz: We often provide default constructors. It's implicit constructors that we don't provide. Commented Apr 5, 2013 at 14:24

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.