Search code examples
c++move-assignment-operator

Does move assignment break the references?


I don't understand if a move assignment is able/free to change the address of a variable x and invalidate all the pointers and references storing &x. I figure that it's false because a default move assignment move each member and preserve the this pointer but is it guaranteed ?

EDIT : Example

int x(1), y(2);
int& ref(x);
x = std::move(y);
// ref still valid ?

Solution

  • Moving to or from an object does not invalidate references or pointers to the object. The address of both objects remains the same.