I have a vector of class "Account". It's private to a class BankingSystem. Here's how I have them defined.
Account Class:
struct newAccount
{
string firstName;
string lastName;
string accountPass;
int accountID;
float accountBalance;
}; //end of structure newAccount
class Account
{
string firstName;
string lastName;
string accountPass;
int accountID;
float accountBalance;
private:
int depositAmount;
int withdrawAmount;
public:
static newAccount createAccount( int, float, string, string, string ); //creates new account
void deposit( int ); //deposits money into account
void withdraw(int); //withdrawals money from account
int retdeposit() const; //function to return balance amount
friend class BankingSystem;
}; //end of class Account
BankingSystem Class:
class BankingSystem
{
int accountID;
char fileName;
private:
std::vector<Account> accounts_;
public:
static void addAccount();
static void storeAccount( newAccount );
void deleteAccount();
void accountInquiry();
void saveAccounts();
void loadAccountsFromFile();
friend class Account;
}; // end of class BankingSystem
I'm trying to store new accounts in the vector in this manner.
1) addAccount function in BankingSystem.h
void BankingSystem::addAccount()
{
int ID;
float balance;
std::string pass, first, last;
cout << "\n\t Enter the Account ID: ";
cin >> ID;
cout << "\n\t Enter the passcode: ";
cin >> pass;
cout << "\n\t Enter Client's first name: ";
cin >> first;
cout << "\n\t Enter Client's last name: ";
cin >> last;
cout << "\n\t Enter starting balance: ";
cin >> setw(6) >> balance;
storeAccount( Account::createAccount( ID, balance, pass, first, last ) );
return;
}
2) createAccount in Account.h
newAccount Account::createAccount( int ID, float balance, string first, string last, string pass )
{
newAccount a;
a.accountID = ID;
a.accountBalance = balance;
a.firstName = first;
a.lastName = last;
a.accountPass = pass;
return a;
}
3) storeAccount in BankingSystem.h
void BankingSystem::storeAccount( newAccount a )
{
accounts_.push_back(a);
}
Everything is working fine except storing data in the vector. The line accounts_.push_back(a);
has this error; "invalid use of member 'accounts_' in static member function."