Ok I'm thinking of makeing a game and the guy will be made up of some vairables like
life
money
damage
and stuff like that would it be a good idea to put them all into a class?
Ok I'm thinking of makeing a game and the guy will be made up of some vairables like
life
money
damage
and stuff like that would it be a good idea to put them all into a class?
+++
++
+ Sekti
++
+++
That's a good time to use a struct. Something like
struct guy
{
int life;
int money;
int damage;
//other stuff here
}
int main ()
{
guy me;
me.life = 100;
me.money = 8;
me.damage=40;
...
return 0;
}
when you put
guy me;
what exactly are you doing I mean I know to do that but what is that doing and if I did that in main would
me.life
work in all other functions?
+++
++
+ Sekti
++
+++
"guy me;" makes an instance of the struct guy. It's just like making an instance of a class. It's scope is the same as any kind of variable (it depends on where you declare it).
Last edited by tim545666; 03-01-2002 at 08:24 PM.
Maybe it will make more sense if I use better names.
Code:struct personsData { int life; int money; int damage; //other stuff here } int main () { personsData John; John.life = 100; John.money = 8; John.damage=40; ... return 0; }
With how you have it will john work in another function later?
Just like an integer, float, double, bool, or any other type of data.Code:struct personsData { int life; int money; int damage; //other stuff here } void test (personsData); int main () { personsData John; John.life = 100; John.money = 8; John.damage=40; ... test (John); return 0; } void test (personsData John) { cout << "JOHN'S LIFE IS " << John.life; }