Please post the entire class definition for Account and for Bank.
From class Account { to }; and the same for Bank. (For this part, I'm not really interested in member bodies, I just want a feel for what data items the class contains and the methods you have defined.)
Then I would like to see the contents of the constructors for Account and Bank.
Murtan
Practically a Master Poster
671 posts since May 2008
Reputation Points: 344
Solved Threads: 116
The default constructor for Account:
Account::Account(){
customer = NULL;
strcpy(customer, ",,,;");
strcpy(accountNumber, "000000000000000");
balance = 0;
}
Is what gets called when you call new Account[arraySize]
On line 2 of the code above, you set customer to point to NULL.
Then on line 3, you attempt to strcpy into the NULL
Very bad form. You need to either declare customer like a bigger accountNumber, or you need to allocate the space you want with something like customer = new char[251]; and then make sure to delete it in the destructor. (The only problem is that the copy constructor just makes a copy of the pointer. If you decide to allocate the customer, the copy constructor will too.)
PS - if you define a copy constructor, you almost always want to define an assignment operator (operator =) to make sure the handling is the same in both cases.
Fix that and see if your problem goes away.
Murtan
Practically a Master Poster
671 posts since May 2008
Reputation Points: 344
Solved Threads: 116
> char *customer; //251 including null byte
> char accountNumber[20 + 1]; //16 including null byte
This is C++, use std::string and move on?
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953