error C2106: '=' : left operand must be l-value

I am making a bank account program for a project. It contains a class for an account which stores the balance of the account and other things such as account number, interest rate etc. I am also required to have a transaction class that deals with withdrawals and deposits.

I have a function in my Account class which returns the balance of an account as the actual balance variable is private so it cannot be directly changed.

I have been working on this project most of the day so it might be a silly little error but basically i get the error 'error C2106: '=' : left operand must be l-value' at compilation from this code in my Transaction class:

#include "transaction.h"

Transaction::Transaction(){;}

void Transaction::withdraw(Account &theAcc, double amount)
{
theAcc.getBalance() -= amount;
}

void Transaction::deposit(Account &theAcc, double amount)
{
theAcc.getBalance() += amount;
}

In main i will pass an account to the function by reference and an amount to withdraw from the account.

I understand the error perfectly as i can see that the error basically instructs me to do this:

void Transaction::deposit(Account &theAcc, double amount)
{
amount += theAcc.getBalance();
}

That compiles and runs, but obviously that is changing the account variable and not the balance....

Can somebody give me some advice on how to actually make it so i can achieve this.

Many thanks again.
You can't increment a function's return value (and even if you could, it'd be pretty pointless). You should make Account::balance public and instead do theAcc.balance+=amount;
yes of course, i realised after about the silly mistake of trying to increment a return value lol. Been a long day. Thanks for the quick reply.
Topic archived. No new replies allowed.