kvarnerexpress 0 Report post Posted February 20, 2005 if i'm using enums, i can use it as the variable name and as a numerical value, correct?ex: enum dayOfWeek {monday, tuesday, wednesday};dayOfWeek day;day=monday;orday=1;or it can only be used one way?please help Share this post Link to post Share on other sites
miCRoSCoPiC^eaRthLinG 0 Report post Posted February 20, 2005 if i'm using enums, i can use it as the variable name and as a numerical value, correct? ex: enum dayOfWeek {monday, tuesday, wednesday}; dayOfWeek day; day=monday; or day=1; or it can only be used one way? please help 52409[/snapback] I believe you refer to the enum list using the variables that you have specified inside.. I'm not sure whether you can refer to it using the index number.. i.e. i've always used it in the form: day = monday, though I'd say there's no reason why you shouldn't be able to use an integer instead of the variable name... If you want more details on enum, follow these links: 1. http://www.functionx.com/cpp/Lesson07.htm 2. http://forums.xisto.com/no_longer_exists/ 3. http://forums.xisto.com/no_longer_exists/ 4. http://forums.xisto.com/no_longer_exists/ Hope this helps Share this post Link to post Share on other sites
osknockout 0 Report post Posted February 21, 2005 I think it's only defined in a hash format (day="monday")but can be made for an index format. Last time I wasat odds with the issue, it changed from standard to standardeven across compilers. Even we sages do not know now ... so tell us what you find. Share this post Link to post Share on other sites
dexter 0 Report post Posted February 21, 2005 Well since dayOfWeek is now a new type, to be able to make day = 1 work, you actually have to use, day = (dayOfWeek)1;The question that begs to be asked is "Why?". Enums are there to make your life easier, in both writing and maintaining the code (meaning you don't have to remember exact values, just names... much easier.But basically, they are just like declaring some constants and using them with an integer... const monday = 1;const tuesday = 2;const wednesday = 3;int main(){ int day = monday; if(day == monday) { .... You get the picture... using enums is just a simpler way of doing that.Also, I might mention that enums start at 0 usually by default, but you can change that by declaring... (in this case), enum dayOfWeek {monday = 1, tuesday, wednesday };Hope that answers your question. Share this post Link to post Share on other sites
fffanatics 0 Report post Posted April 14, 2005 It would work both ways but for one it is normally common practice to make all enums capital because they act as constants. Ex. enum daysofWeek {MONDAY};Secondly, you can not use it like today = 0; you would have to cast the 1 to a daysofWeek like today = (daysofWeek)0; Share this post Link to post Share on other sites