Jump to content
  • Advertisement
Sign in to follow this  
charlando

for inside class

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

I was wondering if the following code would do what i wanted it to...
Quote:
class Character(); { private: SDL_Rect clip[19]; for i = 0 To 19 { clip.x = 16*i; clip.y = 32*i; clip.w = 16; clip.h = 32; }
This is meant to create clip[0 to 19] with the correct variables for each clip. Also does this automatically initialize inside a class?

Share this post


Link to post
Share on other sites
Advertisement
Assuming this is C++, you'll need to put the for loop inside the constructor for the class. Ex:

class Character {
private:
SDL_Rect clip[19];
public:
Character() {
for (i = 0; i < 19; i++) {
clip.x = 16*i;
clip.y = 32*i;
clip.w = 16;
clip.h = 32;
}
}
};

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!