Jump to content
  • Advertisement
Sign in to follow this  
Dandi8

An unknown-size array in a struct

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

Hey guys!
It's late and I'm tired and I probably shouldn't post it but I was hoping you guys could help me with a teeny tiny problem I'm having.

I want to make a struct which has an array in it. But not just any array. Each struct instance would have its own number of items in the array so it would have to be something like this:


struct sSprite{
sSpriteFrame spriteFrame[numOfTilesInSpriteSheet];
sTexture Texture;
};


I would then call make an sSprite like so:

sSprite mySprite[numOfTilesInSpriteSheet];


...Of course, if that was working code. Sadly, it isn't.

So could someone please tell me how to turn this wannabe code into a reality, kthx?

Would really appreciate it as it's blocking me from my wonderful idea of storing sprite collision data in an efficient way ^^

Share this post


Link to post
Share on other sites
Advertisement
Dynamic arrays, C++ style:

std::vector<sSpriteFrame> spriteFrame;

Then somewhere in your constructor/initialization:

spriteFrame.resize(numOfTilesInSpriteSheet);

From then on you can use operator[] just like you would a regular array. Check out MSDN to see what else you can do with vectors.

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!