Need your help deciding if this is an acceptable use of an unnamed enum.
CAttributes is shown bellow. It's a class responsible for storing, managing and displaying a set of attributes from a monster, player or npc character. The sole data member is an unsigned long with the packed value of these attributes. Attributes range from 1-20 (5 bits). There are 6 attributes.
Code:
namespace attributes {
class CAttributes {
public:
explicit CAttributes(const unsigned long val): attrs_(val) {}
~CAttributes() {}
unsigned long get();
void change(int, unsigned int);
unsigned int strength() const;
unsigned int dexterity() const;
unsigned int constitution() const;
unsigned int intelligence() const;
unsigned int smartness() const;
unsigned int sanity() const;
private:
unsigned long attrs_;
};
enum { STRENGTH, DEXTERITY, CONSTITUTION, INTELLIGENCE, SMARTNESS, SANITY };
/* Non members */
unsigned int strength(unsigned long);
unsigned int dexterity(unsigned long);
unsigned int constitution(unsigned long);
unsigned int intelligence(unsigned long);
unsigned int smartness(unsigned long);
unsigned int sanity(unsigned long);
unsigned long genAttrib(unsigned int, unsigned int);
}
The unnamed enum is as the second argument to the void change(int val, unsigned int at) member function. val is how much the attribute is to be added or subtracted, at is what attribute is to be changed. Inside the function there exists a switch based on at.
A user of the class can thus use the class as this:
Code:
// Instantiate a CAttributes with random attributes on the range [10,18]
attributes::CAttributes myattrs(genAttrib(10,18))
myattrs.change(2, attributes::STRENGHT); // add 2 to strenght;
myattrs.change(-1, attributes::DEXTERITY); // subtract 1 to desxterity;
Is this an acceptable use for an unnamed enum considering the needs of the change() function, as an alternative to have 6 member functions, one for each attribute?
On that case would you have it declared as non-member or member? Seems to me I add nothing by declaring it a member and I complicate things further by forcing yet another scope on anyone wanting to use it.