-
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
-
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.
-
Thanks sly - I will keep that it mind
-
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.