| | 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 |
|
|
QUOTE(kvarnerexpress @ Feb 21 2005, 03:54 AM) 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 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://cplus.about.com/od/learnin2/l/aa082104e.htm 3. http://www.cplusplus.com/doc/tutorial/tut3-6.html 4. http://cplus.about.com/od/beginnerctutorial/l/aa021702a.htm Hope this helps
I think it's only defined in a hash format (day="monday")
but can be made for an index format. Last time I was at odds with the issue, it changed from standard to standard even across compilers. Even we sages do not know now ... so tell us what you find.
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... CODE 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.
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; |
|
![]() Enums |
| ADD REPLY / Got an Opinion! | a humble request :-) | RAPID SEARCH! | Free Hosting | [X] |
|
Express your Opinions, Thoughts or Contribute your information that might help someone here. Ask your Doubts & Queries to get answers.. "Together, We enlight each other!" |
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP. | 500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE |
|