Thread: Difference in outlook

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688

    Difference in outlook

    is there any difference in the following:

    Code:
    struct Player
    {
        static int s_hp;
    };
    
    int Player::s_hp = 100;
    
    to this:
    
    class Player
    {
    public:
        static int s_hp;
    };
    
    int Player::s_hp = 10;
    what is better to use, I need to use static variables so I can pass a changed
    value to a new function

    thanks - pete

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    In C++, those are exactly the same, with the exception of the assigned values to s_hp, of course. One is not better than the other as they're pretty much interchangeable. My rule, is generally this... if the entire structure is going to be public, I use struct, if something is private or protected, I use class.
    Sent from my iPadŽ

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Thanks sly - I will keep that it mind

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Another common rule of thumb is to use struct when it will only contain public member variables and no functions, although I personally tend to do the same as SlyMaelstrom.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Difference Equations / Recurrence Relations
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-05-2007, 10:26 AM
  2. What's the difference between var++ and ++var
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 05-31-2007, 02:27 AM
  3. Familar with Outlook Express?
    By Shadow in forum Tech Board
    Replies: 1
    Last Post: 05-22-2004, 01:45 PM
  4. Replies: 8
    Last Post: 09-22-2003, 01:31 PM
  5. Difference between macro and pass by reference?
    By converge in forum C++ Programming
    Replies: 2
    Last Post: 02-26-2002, 05:20 AM