我想知道是否可以在枚举中包含一个数组值?示例
enum RGB {
RED[3],
BLUE[3]
} color;
那样 RED
可以包含 (255,0,0)
的值,因为这是红色的 RGB 颜色代码。
最佳答案
你不能那样做。 enum
中的标记只能包含整数值。
可能的解决方案:
struct Color {uint8_t r; uint8_t g; uint8_t b;};
Color const RED = {255, 0, 0};
Color const GREEN = {0, 255, 0};
Color const BLUE = {0, 0, 255};
关于C++ 在枚举中有数组值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37729672/