Why do we need to set other._p_vals pointer to NULL? Once we set it to NULL, when the
destructor of other is called, it will delete NULL, which is harmless, but it will not release the memory.
Rvalue References and Move Semantics in C++11 - Cprogramming.com
Code:Code:class ArrayWrapper { public: // default constructor produces a moderately sized array ArrayWrapper () : _p_vals( new int[ 64 ] ) , _size( 64 ) {} ArrayWrapper (int n) : _p_vals( new int[ n ] ) , _size( n ) {} // move constructor ArrayWrapper (ArrayWrapper&& other) : _p_vals( other._p_vals ) , _size( other._size ) { other._p_vals = NULL; other._size = 0; } // copy constructor ArrayWrapper (const ArrayWrapper& other) : _p_vals( new int[ other._size ] ) , _size( other._size ) { for ( int i = 0; i < _size; ++i ) { _p_vals[ i ] = other._p_vals[ i ]; } } ~ArrayWrapper () { delete [] _p_vals; } private: int *_p_vals; int _size; };