0

When using an enum in C++, I like to use EnumName::Value (as opposed to just Value). In C++ this is either a warning or an error, depending on compiler settings.

In XCode, what's the name of the setting that will allow me to not have this come up as a compiler error?

enter image description here

(Taking the ErrorLevel:: away resolves the error)

bobobobo
  • 64,917
  • 62
  • 258
  • 363
  • AFAIK in standard C++ it's just an error (unless you are using C++11 "enum classes"). – Matteo Italia Sep 24 '12 at 16:06
  • VC++ flags it as warning [C4482](http://msdn.microsoft.com/en-us/library/ms173704(v=vs.80).aspx). This came up because I imported this same code (from another xCode project) and suddenly the error appeared. There must be some setting that causes it to come up as an error. – bobobobo Sep 24 '12 at 16:09
  • The fact is that it *is* an error as far as the standard is concerned, the fact that VC++ allows it is a nonstandard extension. – Matteo Italia Sep 24 '12 at 16:45

1 Answers1

1
  • if you use , your syntax is correct:

    enum EnumName
    {
    Value 
    }
    ...
    EnumName n = EnumName::Value;
    

    Also note, that if you use , you can require usage of EnumName::Value instead of just Value by using enum class instead of enum:

    enum class EnumName
    {
    Value 
    }
    ...
    EnumName n = EnumName::Value; //ok
    EnumName fuuu = Value; // compilation error
    
  • otherwise, you can wrap your enum declaration with namespace

    namespace EnumName {
    enum EnumName
    {
    Value 
    }
    }
    ...
    EnumName::EnumName n = EnumName::Value;
    
Lol4t0
  • 12,444
  • 4
  • 29
  • 65