Question: We are trying to make Transaction class a private class within the Account_class, thus moving the whole definition of Transaction Classes operator inside the Transaction
We are trying to make Transaction class a private class within the Account_class, thus moving the whole definition of Transaction Classes operator inside the Transaction class. Im getting an error which says that Overloaded 'operator<<' must be a binary operator (has 3 parameters). How to make it work?
class Account_class {
friend ostream& operator<<(ostream& os, const Account_class& theAccount);
friend void readTransaction (vector & act_cl);
public:
Account_class(string& name, int account_number) : name(name), account_number(account_number){
}
void deposit(int amount) {
balance += amount;
Transaction transaction ("deposit", amount);
tr.emplace_back(transaction);
}
void withdrawal(int amount) {
balance -= amount;
if (balance < amount) {
cerr << "Insufficient Funds" << endl;
}
Transaction transaction ("withdrawal", amount);
tr.emplace_back(transaction);
}
private:
class Transaction {
friend ostream & operator << (ostream& transcation_os, const Transaction& theTransaction);
public:
Transaction(string type, int amount) : action(type), amount(amount) {}
// The error occurs in the following lines:
ostream & operator << (ostream& transcation_os, const Transaction& theTransaction) {
transcation_os << theTransaction.action << " " << theTransaction.amount << endl;
return transcation_os;
}
private:
string action;
int amount;
};
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
