This topic is now archived and is closed to further replies.

object creation at runtime confusion

This topic is 5508 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If I am creating a whole load of objects, in this case spawning x file meshes from a text file, is the best way to go about this to declare a huge array of objects and fill the array with however many are stipulated in the file- this is what I am doing at the moment, it works fine, when the objects are initialised they add themselves to a linked list- or is there a better more dynamic way of doing this? Ideally I would like to create the objects on the fly, be there 3 or 300 of them described in the text file. Am I bound to use an array, declared to be the maximum amount of dx meshes i think will be in one scene? And I can''t go through the file once to determine the number of objects that I will need and then create an array of that size can I (here my c++ fails me) when you declare an array the compiler can''t handle that array not being specific when it compiles, am I right?

Share this post

Link to post
Share on other sites
use a pointer, and dynamically allocate the objects:
MyClass* DaList;
num = FindNumberOfObjectsInFile();
DaList = new MyClass[num+1];
for(int t = 0; t < num; ++t)
// ...
delete[] DaList;

[edited by - krez on November 19, 2002 7:32:58 PM]

Share this post

Link to post
Share on other sites