-
Dynamic Arrays
k i'm basically replicating the vector class.
I have ALOT of code which uses the fixed array of 10 elements. I have two classes being used also. The dynamic array would be used in a class.
So so far this is what i have for the fixed Private section of the class:
static const int MAX = 10;
T data[MAX];
and then within the class implementation, i have numersoun functions that use this array. My question is: wat would be the easiest way to convert this class to a dynamic array.
Would i change the above code to:
static int MAX = 10;
T *data;
and then would i have to sort through the class and wherever there is an element being added to the erray i would check for the current size of the array and if it's too small i would use the 'new' to increase the size of the array?
T *data = new T(MAX + 10);
would taht work?
Someone please help, there is just SO much code that i can't figure this out.
Thanx,
D!m
PS. Sorry for the length.
-
Quote:
static int MAX = 10;
That would cause all instanced objects to have that size, i think you mean to leave out static.
you would have to keep count on the amount of allocated memory as well, or alternatively check if the modulus with 10 is 0
remember to delete[] your array in the destructor or whenever you resize it
-
I would have to initialize the MAX in one of the constructors right, can't do it in the class def?
-