![]() |
|
#1
|
|||
|
|||
Looping with enumCPP / C++ / C Code:
|
|
#2
|
|||
|
|||
Re: Looping with enumQuote:
CPP / C++ / C Code:
Output: Code:
Regards, Dave |
|
#3
|
|||
|
|||
Re: Looping with enumIn addition to what davekw7x have shown, below is another example on the looping.
CPP / C++ / C Code:
Hope this helps!!! |
|
#4
|
|||
|
|||
Re: Looping with enumThanks a lot Dave..
I was trying to do the i++, didn't think of casting the i+1 to myenum type. |
|
#5
|
|||
|
|||
Re: Looping with enumQuote:
This highlights some of the differences between enums in C and enums in C++. See footnote. In C, enums are merely a notational convenience for named integers. (That is, an enum is actually an int data type.) In C++ enums are their own data type with a few interesting features: 1. There are no '+' or '++' or other arithmetic operators for enums in C++ (So, if i is an enum data type you can't simply say i++.) 2. In arithmetic expressions involving ints and enum data types, the enum data variables are "promoted" to ints, so the expression i+1 promotes i to an int and adds 1. The result is an int. 3. In C++ you can't assign an integer value to an enum variable without a cast. I used function-style cast, but you could use a C-style cast or a C++ static cast. Regards, Dave Footnote: In C, if i is your enum data type you could simply use CPP / C++ / C Code:
Last edited by davekw7x : 02-Oct-2007 at 10:10.
|
|
#6
|
|||
|
|||
Re: Looping with enumQuote:
...yet another reason why C++ is not a superset of C. :davis: |
Recent GIDBlog
US Elections and the ?Voter?s Responsibility? by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Quick Looping Question | Gamer_2k4 | C++ Forum | 4 | 06-Nov-2006 17:23 |
| Using Enum , and more card stuff | Rob45 | C++ Forum | 1 | 24-May-2006 21:14 |
| Need help with Looping | Harryt123 | C Programming Language | 4 | 21-May-2006 15:45 |
| ask looping | likeit | C Programming Language | 4 | 26-Jul-2005 20:49 |
| Pulldown menu with data from 2 tables or 1 with an ENUM choice? | mytwocents | MySQL / PHP Forum | 1 | 10-Aug-2004 17:30 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The