首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

C++核心准则Enum.5: 不要使用全部大写的枚举值

Enum.5: Don't use ALL_CAPS for enumerators

Enum.5: 不要使用全部大写的枚举值

Reason(原因)

Avoid clashes with macros.

避免和宏定义发生冲突。

Example, bad(反面示例)

代码语言:javascript
复制
 // 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
Enforcement(实施建议)

Flag ALL_CAPS enumerators.

标记全部大写的枚举值。

原文链接:

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#enum5-dont-use-all_caps-for-enumerators


觉得本文有帮助?请分享给更多人。

关注【面向对象思考】轻松学习每一天!

面向对象开发,面向对象思考!

下一篇
举报
领券