Delete lines 14 and 15 and see if the program compiles. If it does, then you know there's a problem. Besides, you initialize balance in line 14, then create the object in line 18.
I'm seeing a problematic lack of a default constructor for this class. If you care what the program initializes everything to(which you clearly do), you should create one. Otherwise the program is free to initialize balance to 92 or anything else it wants.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
You're welcome. Delete lines 14 and 15 of account.cpp. They have nothing to do with you class variable called balance, which is the only balance variable you want.
As for the constructor, stick this in the "public" portion of your class in account.h below line 14.
Account()
{
// stick code here
}
When line 18 of account.cpp...
Accout account1;
executes, the Account() constructor is called. Stick anything that needs to be initialized in there...
Account()
{
cout << "Account() has been called.\n"; // delete this line. I just stuck it in here
// so you can see when it is called.
balance = 0; // this is the line you need to initialize things. Initialize anything
// else inside this function too.
}
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711