|
-
Mar 1st, 2002, 03:10 AM
#1
Thread Starter
Fanatic Member
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.
-
Mar 1st, 2002, 07:47 AM
#2
transcendental analytic
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
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Mar 1st, 2002, 11:24 AM
#3
Thread Starter
Fanatic Member
I would have to initialize the MAX in one of the constructors right, can't do it in the class def?
-
Mar 1st, 2002, 01:23 PM
#4
transcendental analytic
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|