A move assignment operator transfers resources from a source object into an already constructed target. Unlike copying, it gives the target ownership of existing data and leaves the source neutralized. The common mistake is treating this as ordinary member-wise assignment, which can leak resources, duplicate ownership, or leave dangling pointers. section 2.1 section 7.6
A safe move assignment should account for the following:
- Release or otherwise handle resources already owned by the target before taking ownership from the source. section 8.5
- Transfer pointers or other resource handles instead of copying the owned data. section 2.1
- Neutralize the source, commonly by setting transferred pointers to nullptr and resetting related state. section 2.1 section 8.5
- Handle self-assignment and remember that providing one move member can suppress compiler generation of other special members. section 8.5
Replacing an InputReader's resources
A move assignment for InputReader first checks that the source and target differ, deletes the target's filename array, takes the source array and count, then sets the source pointer to nullptr and its count to zero. The target now owns the data, while the source cannot accidentally release or reuse it. section 8.5
InputReader(InputReader&& r) : filenames(r.filenames), count(r.count) {
r.filenames = nullptr;
r.count = 0;
}
InputReader& operator=(InputReader&& r) {
if (this != &r) {
delete[] filenames;
filenames = r.filenames;
count = r.count;
r.filenames = nullptr;
r.count = 0;
}
return *this;
}
The listing provides a compact implementation of move construction and move assignment, including target cleanup, ownership transfer, self-assignment protection, and source neutralization. section 8.5

