In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "C++11 how to specify the size of enum type", in daily operation, I believe many people have doubts on how to specify the size of enum type in C++11, Xiaobian consulted all kinds of information, sorted out simple and easy to use operation methods, hope to answer "C++11 how to specify the size of enum type" doubts helpful! Next, please follow the small series to learn together!
No Scope Specified
The size of an enumeration type automatically adjusts with the range of enumeration values. For example, the following code:
enumer_1 has only two enumeration values, and its size is 4 bytes; the first enumeration value of enumer_2 specifies a number over 32 bits, so the size is automatically adjusted to 8 bytes.
Scope specified
The default size for enumeration types is 4, which is the size of an int. For example, the following code:
The size of scope_enumer_1 can be output correctly, scope_enumer_2 directly raises a compilation error because it specifies a value exceeding 32 bits.
Specify the size of enum
The new C++11 standard allows enum type names followed by colons and types to specify the size of enumerated types. For example, we can specify the size of scope_enumer_2 as 8 bytes:
What's the point?
In short, of course, you can specify the size of the enumeration type. Of course, there is no convincing way to say this, so we will give a few examples:
When you want to save memory space
Enumerated values are exchanged between different operating systems, applications, or versions of applications (files or communications) to avoid incompatibility of data types.
Wait a minute.
At this point, the study of "how to specify the size of enum type in C++11" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.