1234567891011
const std::vector<Account>& getExistingAccount(const std::vector<Account>& acc,const std::string& username) { for ( std::vector<Account>::const_iterator iter = acc.begin(); iter != acc.end(); iter++ ) { if(iter->getUsername() == username) { return *iter; } } return *acc.end(); }
1234567891011121314
// const std::vector<Account>& getExistingAccount(const std::vector<Account>& acc,const std::string& username) const Account& getExistingAccount( const std::vector<Account>& acc, const std::string& username) { for ( std::vector<Account>::const_iterator iter = acc.begin(); iter != acc.end(); /* iter++ */ ++iter ) { if(iter->getUsername() == username) { return *iter; } } // return *acc.end(); // can't dereference acc.end() throw std::domain_error( "not an existing account" ) ; }
return *acc.end();
return Account()