I am making a Bank program that contains 2 classes: Bank and BankAccount. The Bank class contains a list of BankAccounts:
list <BankAccount> userList;
BankAccount contains the following parameters:
double money;
int bank_id;
int person_id;
string name;
string password;
One of the options I want to make is for the Administrator to be able to delete an account. (The Administrator and user menu are not relevant to this problem). To be able to delete an account, the administrator has to provide the "bank_id" which is unique to each type of BankAccount. The problem that I have is that I don't know how to be able to access the object by searching for one of it's parameters. I have tried the following:
bool deleteUserFromList(BankAccount& b1) {
//userList.remove(b1);
list<BankAccount>::iterator it;
it = find(userList.begin(), userList.end(), b1.getBankId());
if (it != userList.end()) {
userList.erase(it);
return true;
}
else {
cout << "Element was not in the list \n";
return true;
}
}
If in the find function I chage the last parameter to just "b1" it will erase the element. But it will only erase them if I provide the object before, not by one of it's parameters (bank_id).
Aucun commentaire:
Enregistrer un commentaire