Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

When does C++ define the underlying types of enumerations

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is mainly about "when does C++ define the underlying types of enumerations", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn when C++ defines the underlying types of enumerations.

Enum.7: define the underlying types of enumerations only when necessary

Reason (reason)

The default type is easier to read and write. Int is the default integer type. Int and C language enumerated types are compatible.

Example (sample)

Enum class Direction: char {n, s, e, w

Ne, nw, se, sw}; / / underlying type saves space

Enum class Web_color: int32_t {red = 0xFF0000

Green = 0x00FF00

Blue = 0x0000FF}; / / underlying type is redundant

Note (Note)

The underlying type of the enumeration needs to be defined when the enumeration is declared before.

Enum Flags: char

Void f (Flags)

/ /....

Enum flags: char {/ *... * /}

At this point, I believe you have a better understanding of "when C++ defines the underlying types of enumerations". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report