Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

When does C++ specify the enumeration value

Shulou Source: shulou.com Published: 2022-06-01 19:21:09 10月06日 Update

The main content of this article is "when does C++ specify the enumeration value", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn when C++ specifies the enumeration value.

Enum.8: specify enumerated values only if necessary

Reason (reason)

It's the easiest way. Duplicate enumerated values can be avoided. By default, a set of continuous values is assigned that can be easily used by switch statements.

Example (sample)

Enum class Col1 {red, yellow, blue}

Enum class Col2 {red = 1, yellow = 2, blue = 2}; / / typo

Enum class Month {jan = 1, feb, mar, apr, may, jun

Jul, august, sep, oct, nov, dec}; / / starting with 1 is conventional

Enum class Base_flag {dec = 1, oct = dec

Tags: Time necessity content situation flag tag learning practicality depth interest reason variable practicality practice suggestion simple operation method more friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Tech Info Shulou Technology macOS vpn