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:
To declare the iterator it,
review how we declared an iterator in Part I of today's exercise.
You will need to do something similar,
but since myAccounts is a map,
you will need to declare this iterator
using a map instead of a set.