Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Why doesn't C++ use all uppercase enumerated values?

Shulou Source: shulou.com Published: 2022-06-01 19:20:17 09月11日 Update

This article mainly explains "why C++ doesn't use all uppercase enumerated values". The content in the article is simple and clear, and it is easy to learn and understand. let's study and learn why C++ doesn't use all uppercase enumerated values.

Enum.5: do not use all uppercase enumerated values

Reason (reason)

Avoid conflicts with macro definitions.

Example, bad (negative example)

/ / 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 errorEnforcement (implementation recommendation)

Marks all uppercase enumerated values.

Thank you for your reading, the above is the content of "Why C++ does not use all uppercase enumerated values". After the study of this article, I believe you have a deeper understanding of why C++ does not use all uppercase enumerated values. the specific use also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Capitalization citation learning content reason reverse that is suggestions ideas situations articles more tags knowledge knowledge points examples articles follow questions conflicts Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information vpn Shulou Tech Info Shulou Technology Microsoft