Hi, I have a list of named enums:

typedef enum EGCDevicePneumaticState { 
EUnknown,
ENotPresent,
ENotReady,
EPressureNotReady,
EFlowNotReady,
EReadyOn,
EReadyOFF,
NumberOfEGCDevicePneumaticState,
};

typedef enum EGCDeviceReadiness { 
EUnknown,
EReady,
EReadForPrep,
ENotReady,
NumberOfEGCDeviceReadiness,
};

typedef enum EGCDeviceRunState { 
EIdle,
EPreRun,
ERun,
EPostRun,
NumberOfEGCDeviceRunState,
};

typedef enum EGCDeviceThermalState { 
EUnknown,
ENotPresent,
EOff,
ENotReady,
EReady,
NumberOfEGCDeviceThermalState,
};

and I am getting errors like:

error C2365: 'EUnknown' : redefinition; previous definition was 'enumerator'
see declaration of 'EUnknown'
error C2365: 'EReady' : redefinition; previous definition was 'enumerator'
see declaration of 'EReady'
error C2365: 'ENotReady' : redefinition; previous definition was 'enumerator'
see declaration of 'ENotReady'

and so on, but these are named, doesn't that mean I can re-use the names for other enums?

Recommended Answers

All 2 Replies

You can't use the same name of the enum's within the same scope.

when you do this:

typedef enum A {
 enum1,
 enum2,
 enum3
};

its about the same as doing this:

const int enum1 = 0;
const int enum2 = 1;
const int enum3 = 2;

So you can see that what your doing is redefining the same variable many times in the same scope.

Ok, yeah I just tested it, I just assumed they were more high-level structures, I guess I will just have to put something before the name, like:

typedef enum A {
      Aenum1,
      Aenum2,
      Aenum3
      };

thanks, the msdn section on enums should say something about that! (though I might of missed it)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.