In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces you what are the keywords of C++, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.
What keywords are there in C++ and what are their uses?
Const and define
Define is the compilation instruction of the precompiler, which is compatible with the C language and works similar to global search and replacement in a text editor. The meaning of the constant defined by define continues from where it begins to the end of the file, and during the precompilation phase, the precompiler has deleted all define and expanded all macro definitions. It only does text substitution, there is no type safety check, the define command will easily introduce errors, and such errors are difficult to find, so C++ uses const instead of define precompiled instructions.
# defineSIGMOID (x) (1 / (1+exp (- x))
Result=SIGMOID (aqb); / / incorrect addition of parentheses will result in incorrect results
Result=SIGMOID ((aqb)); / / correct
Const in the header file
Const defaults to internal links, and if it is placed in the header file, the goal is to make this value available to all compilation units that contain it, and to make only compilation units that contain header files visible. When defining a const, it must be initialized unless an external reference is made with extern. Typically, the C++ compiler does not allocate space for const variables, but the extern keyword forces the compiler to allocate storage space for const variables. Because extern is an external link, you can refer to the const variable for other compilation units. Variables must have storage space.
Note: because the compiler cannot avoid allocating memory for const, const definitions must default to internal links. In C++, whether a const constant is allocated space depends on how it is used: for a constant of the basic data type, the compiler puts it in the symbol table of the target file without allocating storage space, while a custom const object needs to allocate storage space (large objects). There are also situations where storage space needs to be allocated, such as operations such as forcing a declaration as extern or taking an address of a const.
Const keyword and multithread safety
Reentrant is the guarantee of concurrency security, and a reentrant function (the function is not completed and enters the function execution again due to external factors or internal calls) can be safely used in a multi-threaded environment. In order to ensure that a function is reentrant, it must use any (local) static or non-const global variable. At the same time, you cannot return pointers to any (local) static or non-const global variables.
Const in the class
A non-static const variable defined in a class whose different objects can contain a different value. The initialization of const is in the initialization list of the constructor of the class.
Exclusive constants in classes during staticconst-- compilation
Static means that "no matter how many times an object of a class is created, there is only one instance." It must be initialized where it is defined by staticconst. C++ uses it instead of enum (enumerated) to indicate the common properties of objects. It serves the entire class, not an object, so it cannot use a this pointer (the this pointer is used to indicate the calling object when calling a member function), nor can it be copied in the copy constructor. If you take the address of a class's exclusive constant or the compiler insists on seeing a definition, define it with a domain name parser.
This is the end of the keyword sharing about C++. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.
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.