The stub of AccountManager::changeUserName() should look like this:
void AccountManager::changeUserName(const string& oldName, const string& newName) {
}
This method should behave as follows:
- Use myAccounts.find() to get an iterator it pointing to the pair containing userName
and its password.
- If it is different from myAccounts.end():
- Use it->second to retrieve the password, and save it in password.
- Try
- Use erase(it) to remove the
(oldUserName, password) pair from
myAccounts.
- Use createNewAccount(newName, password) to replace it.
If either throws an exception, throw it on to the sender of this message.
- Otherwise: