Rather useing classes on this or not

This is a discussion on Rather useing classes on this or not within the C++ Programming forums, part of the General Programming Boards category; Ok I'm thinking of makeing a game and the guy will be made up of some vairables like life money ...

  1. #1
    Registered User Sekti's Avatar
    Join Date
    Feb 2002
    Posts
    163

    Rather useing classes on this or not

    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
    ++
    +++

  2. #2
    Seņor Member
    Join Date
    Jan 2002
    Posts
    561
    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;
    }

  3. #3
    Registered User Sekti's Avatar
    Join Date
    Feb 2002
    Posts
    163

    when

    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
    ++
    +++

  4. #4
    Seņor Member
    Join Date
    Jan 2002
    Posts
    561
    "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.

  5. #5
    Seņor Member
    Join Date
    Jan 2002
    Posts
    561
    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; 
    }

  6. #6
    Unregistered
    Guest

    Its me sekti im not logged in

    With how you have it will john work in another function later?

  7. #7
    Seņor Member
    Join Date
    Jan 2002
    Posts
    561
    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;
    }
    Just like an integer, float, double, bool, or any other type of data.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 11:47 AM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-24-2004, 12:22 AM
  4. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  5. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 08:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21