Jump to content
  • Advertisement
Sign in to follow this  

An unknown-size array in a struct

This topic is 3078 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
Dynamic arrays, C++ style:

std::vector<sSpriteFrame> spriteFrame;

Then somewhere in your constructor/initialization:


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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!