C++核心準(zhǔn)則Enum.6:避免無(wú)名枚舉

Enum.6: Avoid unnamed enumerations
Enum.6:避免無(wú)名枚舉
Reason(原因)
If you can't name an enumeration, the values are not related
如果你無(wú)法為枚舉命名,說(shuō)明這些值之間沒(méi)有關(guān)聯(lián)。
Example, bad(反面示例)
enum { red = 0xFF0000, scale = 4, is_signed = 1 };
Such code is not uncommon in code written before there were convenient alternative ways of specifying integer constants.
在定義整形常量的便利的候選方式存在之前,這樣的代碼并不少見(jiàn)。
Alternative(可選項(xiàng))
Use?constexpr?values instead. For example:
使用常量表達(dá)式。例如:
constexpr int red = 0xFF0000;
constexpr short scale = 4;
constexpr bool is_signed = true;
Enforcement(實(shí)施建議)
Flag unnamed enumerations.
提示無(wú)名枚舉。
原文鏈接:
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#enum6-avoid-unnamed-enumerations
覺(jué)得本文有幫助?請(qǐng)分享給更多人。
關(guān)注【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!
面向?qū)ο箝_(kāi)發(fā),面向?qū)ο笏伎迹?/span>
評(píng)論
圖片
表情
