When comparing enums that come from different sources such as those of the following code GCC emits warnings. Is there a way to avoid these warnings without c-style casts?
struct Enumerator { enum { VALUE = 5 }; }; template<int V> struct TemplatedEnumerator { enum { VALUE = V }; }; if(Enumerator::VALUE == TemplatedEnumerator<5>::VALUE) { ... }
And GCC emits the following type of warning:
GCC: warning: comparison between 'enum ...' and 'enum ...'
Simple answer in your case: don’t use an
enum, use an inline-definedstatic const int:In this special case, that’s equivalent and all compilers of the last few years should treat it so (I know for a fact that all the major ones do).
See also: static const Member Value vs. Member enum : Which Method is Better & Why?