My problem is with the last part, i e when filling up the default accounts objects with data using the constructor that takes accountNo, balance and interest as input.
THE ISSUES CAME WHEN I changed to using a static array in Customer::Customer() instead of a dynamic one. With the dynamic version of that constructor, the setAccount function (and the rest of the program as well) worked without any issues. But I need to use the static version due to other reasons, so here I am.
private:
int capacity;
string name;
ForeignAccount* accounts;
int numAccounts;
public:
Customer();
virtual ~Customer();
How do I make a version of this that produces the set number of accounts arrays for each customers object using static memory allocation rather than dynamic?
(As for automatic vs static arrays, I have looked into my books and searched the Internet without finding something very clearifying, so I still don't understand why my current solution produces an automatic local array, or even what that really is).
In C and C++, the static keyword means the variable is not visible outside the current translation unit when used at global scope, that only one variable is available to all objects of the class when used within a class definition and, when used in a function, that the variable will only be initialized once and persist for the duration of the program (and won't be visible outside of the function.)
The only way to accomplish what you're asking for is to make accounts a fixed size and keep track of how many accounts are actually there.
I failed to realise that since the fixed size is put on the stack, the array needs to be initialised in the header already so that it gets in there at compile time.