Search code examples
c++move-constructor

default copy move constructor efficiency different


if default copy constructor provider by compiler only make a shallow copy(copy the pointer of a member in heap to target object's corresponding member field), what is the difference between default copy constructor and default move constructor?

I think default move constructor should not be more more efficient than default copy constructor, as no deep copy happened. Am I right?


Solution

  • what is the difference between default copy constructor and default move constructor?

    A default copy constructor does memberwise copy of the data members while a default move constructor does memberwise move of the data members. That is, the default move constructor steal resources instead of copying them from the passed argument.