In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what are the relevant application methods for C++ members". In the daily operation, I believe that many people have doubts about the relevant application methods for C++ members. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what are the relevant application methods for C++ members". Next, please follow the editor to study!
C++ provides an initialization list of C++ class members for the class.
The construction order of class objects is as follows:
1. Any member variable in the class cannot be initialized at definition time.
two。 General data members can be initialized in the constructor.
The 3.const data member must be initialized in the initialization list of the constructor.
4.static is initialized outside the definition of the class.
5. Array members cannot be initialized in the initialization list.
6. You cannot specify an obvious initialization for an array.
Together, these six items illustrate a problem: constant arrays cannot be defined in C++! Because of the contradiction between 3 and 5. This doesn't seem to make sense, huh? I had no choice but to turn to static data members for help.
At this point, my problem is solved. But I would also like to take the opportunity to review the initialization of the C++ class:
1. Initialization list: CSomeClass::CSomeClass (): X (0), y (1) {}
two。 Out of class initialization: int CSomeClass::myVar=3
3.const constant definition must be initialized. Initialization list is used in C++ class.
4. The Category + class cannot define a constant array.
About const, review the constant pointer:
If const is to the left of the asterisk, const is used to modify the variable the pointer points to, that is, the pointer points to a constant; if the const is to the right of the asterisk, const decorates the pointer itself, that is, the pointer itself is constant.
In the C++ class, you must do the following:
1. Must be initialized explicitly with an initialization list for any const or reference type member and any member of a class type that does not have a default constructor
two。 Class members cannot be initialized at definition time.
3. The initialization order of class members is independent of the post-election order of member variables in the constructor, but related to the order in which member variables are defined in the class.
So the following example is wrong:
Class x {int i; int j; public: X (int value): J (value), I (j) {}}
For the above code, there is a problem with execution because I is initialized first (I is first defined relative to j) and j is not initialized during I initialization.
At this point, the study of "what are the relevant application methods for C++ members" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.