Hello,
I've coded the following which works to a certain extent! I've managed to get the vectors working with int but not with my class...
#include <iostream>
#include <vector>
using namespace std;
class BankAccount
{
public:
//void setAccount(int num, double amount); taken out replaced by constructor
BankAccount(int num, double amount);
BankAccount();
int getBalance();
int getAccountNumber();
void deposit(double AnAmount);
void withdraw(double AnAmount);
private:
int accountNumber;
int Balance;
};
BankAccount::BankAccount()
{
accountNumber = 1;
Balance = 0;
}
BankAccount::BankAccount(int num, double amount)
{
accountNumber = num ;
Balance = amount ;
}
int BankAccount::getBalance()
{
return Balance;
}
int BankAccount::getAccountNumber()
{
return accountNumber;
}
void BankAccount::deposit(double AnAmount)
{
Balance += AnAmount;
}
void BankAccount::withdraw(double AnAmount)
{
Balance -= AnAmount;
}
int main()
{
BankAccount b;
vector<BankAccount>b1(10);
cout << b1.size() << endl;
cout << b1.capacity();
b1.push_back(b);
cout << b1.capacity();
cout <<"The vector contains" << endl;
for(int i = 0; i < b1.size(); i++)
cout<< b1[i] << endl;
return 0;
}
the Error I receive upon compilation is:
C:\computer science programming\CPP2\excerise sheet 9\question 1\vector of bankAccounts\bankaccounts.cpp(74) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class BankAccount' (or there is no acceptable con
version)