Jump to content
  • Advertisement
Sign in to follow this  
ViperG

Question about STL

This topic is 4997 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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!