![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2004
Posts: 29
Rep Power: 0
![]() |
Enumerations as loop variables
I've been programming in C mostly, and I've become accustomed to being able to do things like this:
typedef enum TEST_ENUM_t
{
TEST0,
TEST1,
TEST2,
TEST3
} TEST_ENUM_t;
TEST_ENUM_t TestIndex;
for (TestIndex = TEST0; TestIndex <= TEST3; TestIndex++)
{
// Do something
}Well, now I'm trying to do something like this for some test driver software written in Visual C++ which will be used to test C functions. When I attempt to do something like I have above in Visual C++, I get the following error: error C2676: binary '++' : 'TEST_ENUM_t' does not define this operator or a conversion to a type acceptable to the predefined operator Is there a way to do something similar to the code above in Visual C++? Thank you. |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
In C an enum is an int. In C++ it is not. It is, in fact, its own datatype. One result of this is that the typedef is no longer required. Another result is that you can no longer perform normal arithmetic on it.
Is there any particular reason that you haven't merely defined TestIndex as an int?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2007
Posts: 24
Rep Power: 0
![]() |
I think it should work if you do something like this:
typedef enum TEST_ENUM_t {
TEST0 = 0,
TEST1,
TEST2,
TEST3
}; |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Doesn't change a thing. TEST0 is, by default, zero.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| for loop variables | emdiesse | Java | 8 | May 17th, 2007 10:20 PM |
| Hanging For loop in C++ | can342man | C++ | 20 | Apr 30th, 2006 7:27 AM |
| Help in QBASIC (I think it's similar to VB) | phoenix987 | Visual Basic | 3 | May 9th, 2005 12:33 PM |
| Help with a QBASIC program | phoenix987 | Other Programming Languages | 4 | May 5th, 2005 12:27 PM |
| Timing loop problems | badbasser98 | C++ | 11 | Mar 10th, 2005 8:30 PM |