In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains why C++ enumerates types are better than macros. Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn why C++ enumerated types are better than macro definitions.
Enum.1: enumerated types are better than macro definitions
Reason (reason)
Macro definitions do not need to follow scope and type rules. At the same time, macro definition names are replaced at precompiled extremes, so they usually do not appear in tools such as debuggers.
Example (sample)
The first is some bad old-fashioned code:
/ / webcolors.h (third party header)
# define RED 0xFF0000
# define GREEN 0x00FF00
# define BLUE 0x0000FF
/ / productinfo.h
/ / The following define product subtypes based on color
# define RED 0
# define PURPLE 1
# define BLUE 2
Int webby = BLUE; / / webby = = 2; probably not what was desired
Use enumerations instead of:
Enum class Web_color {red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF}
Enum class Product_info {red = 0, purple = 1, blue = 2}
Int webby = blue; / / error: be specific
Web_color webby = Web_color::blue
We can use enumeration classes to avoid name conflicts.
Enforcement (implementation recommendations)
Marks the macro definition of the integer type.
At this point, I believe you have a better understanding of why C++ enumerated types are better than macros, so 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.
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.