object creation at runtime confusion

Started by
1 comment, last by feet dont fail me now 21 years, 4 months ago
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?
Advertisement
use a pointer, and dynamically allocate the objects:
MyClass* DaList;num = FindNumberOfObjectsInFile();DaList = new MyClass[num+1];for(int t = 0; t < num; ++t)  LoadObjectFromFileIntoObject(DaList[t]);// ...delete[] DaList;  


[edited by - krez on November 19, 2002 7:32:58 PM]
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
oh krez a million thanks.
this forum amazes! a post, a reply, a test and a solution, a turnaround of a quarter of an hour!
one more thanks on top of the million.

This topic is closed to new replies.

Advertisement