1. If I want to represent a bunch of the same critters in a game I'm making with objects of the same class, what would I use for the health meter as a part of each individual object?
2. What would you use to implement a critter's ability to move?
3. What would most efficiently store the total number of critters created in the game?
A data member or static data member?
A member function or static member function?
Could you please tell me why also. This is for a homework assignment and the book doesn't elaborate very well. Thanks in advance.
Try to understand the differences between the 4 given possible answers, and what their specializations are.
A data member is just a place to store data per instance of a class.
A static data member is a place to store data per class.
A member function is a function that has access to data members and static data members.
A static member function is a function that has access to static data members ONLY.
static vars/functions are shared for ALL objects. So if one objects changes them, the changes are seen by ALL objects.
non-static vars/functions are owned by each individual object, so an object can change them without it impacting other objects.
If you use a static data member for the life of the critters, then when one critter's life changes, all of their life will change because they're all sharing the same life.