Tony isn't really right when he suggests you use a static method!
Because your function - correctly - accesses member variables of the class, you cannot declare it as static. Or if you do, the member variables have to be statiuc as well, and that means that your whole app can only have one account name, balances, and so on.
Which isn't what you want - in the real world, each bank account is separate - it doesn't matter how much money you have in your account, I can only spend what I have in mine, and vice versa.
That's what classes are there for: the keep related data together in what is called an
- your account is one instance, my account is a different instance.
It;'s just like cars: your car is different from my car, they are separate instances. If you put your mobile in the glove box of your car and then we go for a drive in my car, would you expect to find your mobile in my glove box? Of course not! You understand instances, just you never thought of them by that name, is all.
So what you actually need to do is create an instance of your class and then use that to call the
function so that it fills the information into the right instance: