Hello
I am slowly learning more and more about C++ and more importantly programming technique and I have reached the wall that I am sure quite a few before me have probably hit - refrences/pointers and management of the heap. Whilst I try and familiarize myself with the above, I am trying to stay ontop of the stuff that I have already learnt, but in doing this have met another wall in which I believe is quite important to get past.
I have basically made a bank account program with help from another question I asked here, and have got to the point where I would like to implement a createNewAccount() method, which at first seemed pretty simple to me until I had a good think about it and how it would be done.
The problem I am having is creating objects inside of the program, is this even possible? From my understanding, each bankAccount must have its own object named appropriatly and this is what I am struggling to achieve. For example, for my case I could just use the accountID for the name of each object and have a method as following which would in turn produce the constructor which would sort everything else out.
void createNewAccount()
{
bankAccount lastAccNumber++
}
Is this above even possible? Can you make an object using the contents of variables in this fashion? Or must it always be a predefined string?
If the above is actually do able, as said above it would work in my case, but what do you do if the object you are using that does have a incremental key field like for example Flowers or Coins?
I know it is a very large question and probably not explained well, but the topic is really something I need to understand and any help on it would be greatly appreicated.
Thank you
class bankAccount
{
public:
bankAccount() : accNumber(lastAccNumber++), accBalance(0) {};
int getNumber() const { return accNumber; }
int getBalance() const { return accBalance; }
void plusBalance(int amountAdded) { accBalance = accBalance + amountAdded; }
void minusBalance(int amountMinus) { accBalance -= amountMinus; }
private:
int accNumber;
int accBalance;
static int lastAccNumber;
};
int bankAccount::lastAccNumber = 1;