First of all, it sounds like you want your 'array' to be of dynamic length. If this is the case, I highly recommend you use a vector instead of array. If using an array, you might do something like this:
However, if you decide to use a vector, it might look something like this:Code:// Creates the array // Have MAX_LIST_LENGTH defined beforehand, or just use literal here: TEnt list[MAX_LIST_LENGTH]; // ahoodin is right. put * symbol between 'TEnt' and 'list' on this line // loop through the array, creating and adding elements for(int i = 0; i < MAX_LIST_LENGTH; i++) { pos.Initialize(x,y,z); list[i] = new TEnt(pos); }
Or, I could be totally off base here. Let me know if this helps.Code:#include <vector> ... std::vector<TEnt> list; for(int i = 0; i < NUMBER_OF_ITEMS; i++) { pos.Initialize(x,y,z); list.push_back(*(new TEnt(pos))); }
Edit: ahoodin (below) is right. I forgot we were working with pointers. Simply add the * symbol in that case.




Reply With Quote