c++ - failed to move contents with std::move -
i'm trying understand how std::move simple example (below). i'm trying move contents of p1 p2, p1 empty after that, doesn't happen though.
i guess i'm not using std::move properly. appreciate lot if explain me.
#include <iostream> #include <utility> int main() { int * p1 = new int[10]; for(int = 0; < 10; ++i) p1[i]=i; // moving contents of p1 p2 int * p2 = std::move(p1); // expeting p1 empty it's not... if(p1 != null) std::cout << "i'm not empty\n"; // prints i'm not empty }
the move function not guaranteed clear contents of source object. is, however, guaranteed left in such state can safely destroy or assign new value it.
Comments
Post a Comment