class thing{blahblahblah};
thing * array[500];
How do I define this dynamically? I don''t know how many there will be. Also I am reluctant to use a linked list because the number won''t change at all and so therefore I don''t need much manipulation - only at loadtime.
I''m sure there must be a way of doing this using new or something...
wise_guy
Arrays of Pointers!
Okay, here''s a tricky question (well, probably not...)
I am trying to use an array of pointers, NOT a pointer to an array. Normally this would be defined as such:
Try this:
typedef thing* thingPointer;
thingPointer * stuff = new thingPointer[500];
typedef thing* thingPointer;
thingPointer * stuff = new thingPointer[500];
I can''t guarantee this''ll work because i''m away from my compiler but maybe try:
Thing* array[] = new Thing*[size];
40
www.databyss.com
www.omlettesoft.com
"Don''t meddle in the affairs of wizards, for they are subtle and quick to anger."
Thing* array[] = new Thing*[size];
40
www.databyss.com
www.omlettesoft.com
"Don''t meddle in the affairs of wizards, for they are subtle and quick to anger."
-40
I use something like this in my game-to-be...
//Ksero
thing **my_pointers;my_pointers = new thing *[num_objects];for(int i=0;i<num_objects;i++)my_pointers<i> = new thing;
//Ksero
I know, I know. I'm weak!!!
YAP-YFIO,
deadlinegrunt
Edited by - deadlinegrunt on August 22, 2000 2:28:01 AM
#include<vector>class thing {/*...*/};typedef std::vector<thing*> vthing;int main(){ vthing thing_array; while(!done) // or you run out of resources I suppose... { thing_array.push_back(new thing); }}
YAP-YFIO,
deadlinegrunt
Edited by - deadlinegrunt on August 22, 2000 2:28:01 AM
~deadlinegrunt
Yeah, I''d use the vector of pointers as well, because I''m a slack bitch.
Maybe use the resize method once rather than push_back for each object pointer, but the main point is avoiding as much work as you can, right?
-------------
squirrels are a remarkable source of protein...
Maybe use the resize method once rather than push_back for each object pointer, but the main point is avoiding as much work as you can, right?
-------------
squirrels are a remarkable source of protein...
if the value won''t change then what are you talking about "dynamically"?
int Elements;
//do calculations on Elements
//get the final data for Elements
thing * pThing[Elements] = new Thing;
int Elements;
//do calculations on Elements
//get the final data for Elements
thing * pThing[Elements] = new Thing;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement