elaborated-type-specifier for a scoped enum must not use the ‘class’ keyword

Why is the compiler producing error even i've enabled -std=c++11

warning: elaborated-type-specifier for a scoped enum must not use the ‘class’ keyword [enabled by default]


my code is something like :
enum class COLOR { RED, GREEN, BLUE };

Compiling though through coliru worked fine
Last edited on
bump

could it be an upgrade issue ? i've recently upgraded my compiler to 4.8.1 from 4.5.
I'm using Slitaz Linux
bump
closed account (j3Rz8vqX)
It isn't an error, it's a warning.

I get it as well.
 
...\main.cpp|7|warning: scoped enums only available with -std=c++11 or -std=gnu++11 [enabled by default]|


Is it effecting your program?
well, the problem is i've enabled
-std=c++11
and i still get the error
The warning says that you can't have scoped enums with the class keyword. That would imply to me that you can get rid of the warning by not including class in your definition of the enum.
i'm actually trying to use C++11's strongly typed enum, and it's syntax should include the class keyword
closed account (j3Rz8vqX)
Don't know how you've actually implemented your enum declaration since you stated that "my code is something like"; if its significantly different, you may get different results.

1
2
3
4
5
enum Enum1;                      // Illegal in C++03 and C++11; the underlying type cannot be determined.
enum Enum2 : unsigned int;       // Legal in C++11, the underlying type is explicitly specified.
enum class Enum3;                // Legal in C++11, the underlying type is int.
enum class Enum4 : unsigned int; // Legal in C++11.
enum Enum2 : unsigned short;     // Illegal in C++11, because Enum2 was previously declared with a different underlying type. 

Referenced from http://en.wikipedia.org/wiki/C++11

Other than that, if you are truly on GCC 4.8.1 and have enabled "-std=c++11", I'm not sure where to go from there.

Maybe someone else will give us input.

Edited:

"Check the type you are deriving the enum class from exists. In this case, there was no typedef specified for int8"
1
2
3
4
5
enum class FaceDirection : int8
{
  Down,
  Up
};

http://stackoverflow.com/questions/20459120/elaborated-type-specifier-for-a-scoped-enum-must-not-use-the-class-keyword

GCC 4.8.2 has just released: http://gcc.gnu.org/
Last edited on
Okay, i've just did some tests and i've realized that the error is caused by something else :

These are simple tests i did

This code worked fine :
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

enum class ECHO { OFF, ON };

void echo( ECHO status )
{
        std::cout << (status == ECHO::OFF ? "off" : "on");
}

int main()
{
    echo( ECHO::OFF );
}



And this one triggers the error:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

#if defined( _WIN32 )
#include <windows.h>
#elif defined( __gnu_linux__ )
#include <termios.h>
#include <unistd.h>
#endif

enum class ECHO { OFF, ON };

void echo( ECHO status )
{
        std::cout << (status == ECHO::OFF ? "off" : "on");
}

int main()
{
    echo( ECHO::OFF );
}


??
test.cc:10:12: error: expected identifier or '{'
enum class ECHO { OFF, ON };
           ^
/usr/include/bits/termios.h:185:14: note: expanded from macro 'ECHO'
#define ECHO    0000010
                ^
oh SHI*, next time, i will carefully read error messages :)

Tnx
Topic archived. No new replies allowed.