Today's code
/* cpp/write */
#include <cstddef>
struct Buffer {
int* data;
size_t size;
Buffer(size_t n) : data(new int[n]), size(n) {}
~Buffer() { delete[] data; }
// write the move constructor here
Buffer(Buffer&& other) noexcept;
};
Implement the move constructor: it should steal other's resources and leave other in a valid, empty state.
Reference
Buffer::Buffer(Buffer&& other) noexcept
: data(other.data), size(other.size) {
other.data = nullptr;
other.size = 0;
}
Take the pointer, don't copy the array. Then null out other so its destructor doesn't free memory *this now owns.