Sign in to follow this  
charlando

for inside class

Recommended Posts

charlando    122
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[i].x = 16*i; clip[i].y = 32*i; clip[i].w = 16; clip[i].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
SiCrane    11839
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[i].x = 16*i;
clip[i].y = 32*i;
clip[i].w = 16;
clip[i].h = 32;
}
}
};

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this