【发布时间】:2017-08-03 11:15:29
【问题描述】:
我有包含该行的代码
enum struct cols: int8_t {red, blue, green};
当我编译这个时,我得到了错误:
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};
^
但是,如果我把这条线
#include <iostream>
在顶部,它毫无怨言地编译。
对此有解释吗?
(我使用的是 g++ 4.9.4,但此行为也显示在 g++ 5.4.0 中。)
【问题讨论】:
标签: c++11 struct enums include enum-class