What happens if you move an object without move constructor?

1.3k views Asked by At

What happens if std::move() is called on a user defined object, that defines no move constructor? Is it simply copied?

1

There are 1 answers

0
AudioBubble On

Yes, move will fall back to copy. This is how standard containers like std::vector can implement resizing in terms of move, but remain compatible with classes which can only be copied.

However, the class may have an implicitly defined move constructor - see this guidance. http://en.cppreference.com/w/cpp/language/move_constructor#Implicitly-declared_move_constructor