Searching Class Variables

So I have a class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class player
{
    public:
        short int health = 5;
        short int damage = 5;
        string name;
};

int main()
{
player one;
one.health = 3;

player two; 

player three;
three.health = 2;
three.damage = 2; 

etc... 


My code actually has 60 instances of the class, most of them deviating slightly from the default variables. How can I search for class members that have certain variables? For example, how to find all players with 5 health, or all players with the same name?

Would it also be good practice to use a header file to define all these things?
Last edited on
store each instance in a vector like:

std::vector<player> playerList;

you can then search this vector using std::find_if. Ofcourse you will have to

#include <vector> and #include <algorithm>

Following link explains http://www.cplusplus.com/reference/algorithm/find_if/
Topic archived. No new replies allowed.