cj92713696
Programmer
I really need some help
I've created an object called SavingsBank; It works
great! It has a constructor of SavingsBank(0, ""
where 0 is my initial balance and "" is the account
name.
I've created a second object called Array1; Array1
will instantiate objects of type SavingsBank and will
trap all errors if I try to go out of bounds of the
array element. It has a constructor of arraySize.
For instance ...
Array1 Jack(5);
Jack[0] through Jack[4] will be normal, but if I try
to access Jack[5] my Array1 class should trap that
error. I've overloaded my [] through class Array1.
The only area I've having problems w/is how to
instantiate an array of my own object. Obviously if I
wanted to have a 5 element array of type int, I could
simple do a ...
int *savingsAccountPtr;
savingsAccountPtr = new int[5];
... and that would work fine, but the only way I know
how to instantiate SavingsBank is as follows ...
SavingsBank *savingsAccountPtr;
savingsAccountPtr = new SavingsBank(0, ""
;
... If I try to add the brackets to SavingsBank it
gives me an error. I imagine I have to overload the
[] in SavingsBank, but I'm still in the same dilemma -
arrays of my own object. Can you help me out here?
I have also done this ...
SavingsBank *savingsAccountPtr;
savingsAccountPtr = new SavingsBank(0, ""
;
for (int intCounter = 0; intCounter < 5; intCounter++)
{
savingsAccountPtr++;
savingsAccountPtr = new SavingsBank(0, ""
;
}
... the problem w/that though is that the memory
locations are not consecutive ... C++ will just find
an area of memory that is free and put a single
instance of my object.
Your help is much appreciated .........
CJ
I've created an object called SavingsBank; It works
great! It has a constructor of SavingsBank(0, ""
where 0 is my initial balance and "" is the account
name.
I've created a second object called Array1; Array1
will instantiate objects of type SavingsBank and will
trap all errors if I try to go out of bounds of the
array element. It has a constructor of arraySize.
For instance ...
Array1 Jack(5);
Jack[0] through Jack[4] will be normal, but if I try
to access Jack[5] my Array1 class should trap that
error. I've overloaded my [] through class Array1.
The only area I've having problems w/is how to
instantiate an array of my own object. Obviously if I
wanted to have a 5 element array of type int, I could
simple do a ...
int *savingsAccountPtr;
savingsAccountPtr = new int[5];
... and that would work fine, but the only way I know
how to instantiate SavingsBank is as follows ...
SavingsBank *savingsAccountPtr;
savingsAccountPtr = new SavingsBank(0, ""
... If I try to add the brackets to SavingsBank it
gives me an error. I imagine I have to overload the
[] in SavingsBank, but I'm still in the same dilemma -
arrays of my own object. Can you help me out here?
SavingsBank *savingsAccountPtr;
savingsAccountPtr = new SavingsBank(0, ""
for (int intCounter = 0; intCounter < 5; intCounter++)
{
savingsAccountPtr++;
savingsAccountPtr = new SavingsBank(0, ""
}
... the problem w/that though is that the memory
locations are not consecutive ... C++ will just find
an area of memory that is free and put a single
instance of my object.
Your help is much appreciated .........
CJ