![]() |
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_tWell, 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 operatorIs there a way to do something similar to the code above in Visual C++? Thank you. |
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? |
I think it should work if you do something like this:
:
typedef enum TEST_ENUM_t { |
Doesn't change a thing. TEST0 is, by default, zero.
|
| All times are GMT -5. The time now is 2:59 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC