paulm
paulm

Reputation: 5882

C++ strongly typed enums in visual studio 2010

When I use a strongly typed enum in VS2010, for example:

enum eTest : long long
{
_test1                  = 0x0000000000000001,
_test2                  = 0x0000000000000002,
};

I get this warning:

http://msdn.microsoft.com/en-us/library/ms173702.aspx

nonstandard extension used: specifying underlying type for enum 'enum'

Why is this? I thought VS2010 supported C++11? Also is a 64bit based enum safe between 64-32bit VS2010 compilers?

Edit:

Regarding the second part of my question: I asked about the 32 vs 64bit because OR'ing bit flags from a 64bit enum when targeting 32bit resulted in compiler errors. However I found out that the reason for is is because enabling Microsoft's Code Analysis causes this to break.

Upvotes: 2

Views: 7250

Answers (2)

Robert Andrzejuk
Robert Andrzejuk

Reputation: 5222

VS 2010 is not a full C++11 implementation: Support For C++11/14/17 Features (Modern C++)

From Microsoft VS2010 documentation: C++ Enumeration Declarations

The definition of a enum:

enum [tag] [: type] {enum-list} [declarator];

type is the underlying type of the identifiers. This can be any scalar type, such as signed or unsigned versions of int, short, or long. bool or char is also allowed.

It doesn't say anything about long long (maybe documentation wasn't updated).

Upvotes: 0

Bob Fincheimer
Bob Fincheimer

Reputation: 18036

C++11 enums are done like this:

enum class eTest : long long
{
    _test1                  = 0x0000000000000001,
    _test2                  = 0x0000000000000002,
};

See Strongly Type Enumerations

[EDIT:] And I believe VS 2010 does not have the compiler that supports this. I think C++11 enums were only partially supported in the MSVC++ 10 Compiler

As far as sizes: check out this page that talks about sizes of data types. Microsoft doesn't vary much between the 32 and 64 bit versions of their compiler.

Upvotes: 3

Related Questions