jeudi 3 août 2017

'enum struct' won't compile unless

I have code that contains the line

enum struct cols: int8_t {red, blue, green};

When i compile this, i get errors:

test.cpp:4:1: warning: elaborated-type-specifier for a scoped enum must not use the 'struct' keyword
 enum struct cols: int8_t {red, blue, green};
 ^
test.cpp:4:13: error: use of enum 'cols' without previous declaration
 enum struct cols: int8_t {red, blue, green};
             ^
test.cpp:4:17: error: expected unqualified-id before ':' token
 enum struct cols: int8_t {red, blue, green};
                 ^

However if i put the line

#include <iostream>

at the top, it compiles without complaint.

Is there an explanation for this?

(I am using g++ 4.9.4, but this behaviour is also displayed with g++ 5.4.0.)

Aucun commentaire:

Enregistrer un commentaire