03 February 2023

C++ 核心指南目录

“Don’t use ALLCAPS for enumerators”

理由

避免与宏名字冲突。

例子

// webcolors.h (third party header)
#define RED   0xFF0000
#define GREEN 0x00FF00
#define BLUE  0x0000FF

// productinfo.h
// The following define product subtypes based on color
enum class Product_info { RED, PURPLE, BLUE };   // syntax error

强化

  • 标记全大写的枚举值