Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

enum.... 1

Status
Not open for further replies.

Sedai

Programmer
Mar 4, 2001
158
US
is there a way to change the value of an enum item with a method as in
Code:
class Hoho{

public:
//...
enum{SOMETHING=5};
void changeSomething(int n){SOMETHING = n;}
private:
//...
};

I get a type mismatch error (no conversion from type 'enum' to 'int'). Any suggestions?
I realize I can have the SOMETHING as a private data member...
thanks :) Avendeval


 
Declaring an enum is a lot like declaring const ints. In your example above, SOMETHING can't be changed - it's really a constant. As far as I know, the primary use for enums is to replace const ints in a way that makes using your code appropriately easier - since (as you've discovered) an enum is NOT an int according to the compiler.
 
well, so it is a dumb question, what im asking lol
thanks guys.
of course it makes sense. thank you both :)
Avendeval


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top