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

## Recommended Posts

The way im using STL's is like this. struct example { int x; }; example *mystruct; vector<example*> myvect; Then I make one so I go: mystruct= new example; mystruct->x=0; myvect.pushback(mystruct); So whenever I want to loop through I just go. for (index=0; index < myvect.size(); index++) { myvect[index]->x++; } That is about as easy as STL's get. My question is, is there a way I can double up on my vectors. in other words, how would my dynamic structure, contain it's own dynamic variables/structure. unit[index]->unit2[index2] ? Or something similure. The only reason for this is when I create my main unit, A space ship, and it has 20 turrets. When the ship blows up, all the ships turrets will need to be killed as well. But the idea here is I can have 10 ships all with their own 20 turrets. Now I could keep my turrets in it's own STL, and have a owner flag= the index of the ship STL. Only problem with that is if I erase a ship, I have to go through the turret STL, and tell it that it's new owner is index-1. That would be of course if the first ship in the index was erased. If I kill the last ship in the STL index, and I tell it to kill the turrets of the owner, it would work fine. Wouldn't have to re-index. The idea here is to keep everything dynamic. I could just use arrays, but then I feel like im wasting memory. I'm open to any suggestions, I don't even know if what I want to do is possible. Or if anyone has a better system when 1 STL is based off the existence of another STL.

##### Share on other sites
There's nothing saying you can't have something like this:

struct ship {  int x, y;  vector <turret *> turrets;}struct turret {  // Whatever turrets have in them these days}...vector <ship *> ships;

You just have to make sure that you initialize the turrets properly and that you clean up after yourself.

If you mean more simply a vector of vectors (no containing class), then you can do this: vector < vector <ship> > ships2DArray; Note the extra spaces. They're needed to differentiate from the right shift operator.

-Auron

##### Share on other sites
Thanks Auron, thats what I needed to know! :D Now if I can just get over this flu. ugh.

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633330
• Total Posts
3011388
• ### Who's Online (See full list)

There are no registered users currently online

×