New blog location
New blog location
cleanup
, moveFrom
, the move constructor and the move assignment operator.void Bank::cleanup() noexcept { delete[] mCheckingAccounts; mCheckingAccounts = nullptr; mName = ""; mNumAccounts = 0; } void Bank::moveFrom(Bank &src) noexcept { //Shallow copy first. Move objects. mNumAccounts = src.mNumAccounts; mCheckingAccounts = src.mCheckingAccounts; mName = std::move(src.mName); //Ownership has moved, reset the source object src.mName = ""; src.mNumAccounts = 0; src.mCheckingAccounts = nullptr; } //Move constructor Bank::Bank(Bank&& src) noexcept { moveFrom(src); } //Move assignment operator Bank&::Bank::operator=(Bank && rhs) noexcept { if(this == &rhs) { return *this; } cleanup(); moveFrom(rhs); return *this; }
Comments
Post a Comment