Enums should work the way you describe. Unfortunately you only provided modified, unrunnable code and no compiler errors or other output. However, the following code should show you how to use enums: (Live demo)
#include <iostream>
enum Race { None, Living, Dead, Nature}; // always put invalid as the 0 entry.
class Player
{
uint32_t m_karma;
bool m_myTurn;
Race m_myRace;
public:
void addPlayer(int x_)
{
std::cout << "added player " << x_ << std::endl;
m_karma = 0;
m_myTurn = false;
m_myRace = None;
}
};
int main(int argc, const char** argv)
{
Player fred;
fred.addPlayer(1);
return 0;
}
If you have a C++11 capable compiler you can be more specific and use "enum Class" which will force you to qualify enumerations (i.e. Race::None). (Live demo)
#include <iostream>
enum class Race { None, Living, Dead, Nature}; // always but invalid as the 0 entry.
class Player
{
uint32_t m_karma;
bool m_myTurn;
Race m_myRace;
public:
void addPlayer(int x_)
{
std::cout << "added player " << x_ << std::endl;
m_karma = 0;
m_myTurn = false;
m_myRace = Race::None;
}
};
int main(int argc, const char** argv)
{
Player fred;
fred.addPlayer(1);
return 0;
}
"player[x].race = None" won't work because that is assignment, not a test for equality. You don't say why it didn't work, I'm going to assume - if it wasn't just the wrong variable name - because it was private or inaccessible. In that case, just add a member function to return the race:
class Player {
...
public:
Race getRace() const { return m_myRace; }
...
};
enum. Also, when you try to do your check, did you actually use=instead of==?