Enum class error


is it known that the following code produces an error, but compiles just fine?

enum class Color {RED, GREEN, BLUE};

Color color = Color::GREEN; //error: 'Taking enum type 'Color' from Integer

if(color == Color::GREEN) { //error: 'Types 'color' and 'int' are not compatible
    cout << "true" << endl;

changing Color color to int color removes the error, but I prefer keeping Color there.

1 comment
Comment actions Permalink

Hi Tim,

Indeed when enum is defined inside function body false error occurs, if definition is placed on a top level CLion code inspections are correct. Here is the related issue https://youtrack.jetbrains.com/issue/CPP-2366 feel free to upvote and leave comments.


Please sign in to leave a comment.