ISO C++ forbids forward references to 'enum' types

Given the program:

enum E : int { A, B, C }; 

g++ -c test.cpp works just fine. However, clang++ -c test.cpp gives the following errors:

test.cpp:1:6: error: ISO C++ forbids forward references to 'enum' types enum E : int ^ test.cpp:1:8: error: expected unqualified-id enum E : int ^ 2 errors generated. 

These error messages don't make any sense to me. I don't see any forward references here.

6

1 Answer

Specifying the underlying type for an enum is a C++11 language feature. To get the code to compile, you must add the switch -std=c++11. This works for both GCC and Clang.

For enums in C++03, the underlying integral type is implementation-defined, unless the values of the enumerator cannot fit in an int or unsigned int. (However, Microsoft's compiler has allowed specifying the underlying type of an enum as a proprietary extension since VS 2005.)

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like