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 > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "how to understand the static member variables and static member functions of C++ class". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!
1. Static member variables of the class
The static member variables of the C++ class mainly have the following characteristics:
1. Static member variables need to be defined within the class and initialized outside the class.
two。 Static member variables do not depend on the class, static member variables belong to the global area, not to the space of the class.
3. Static member variables can be accessed through class names or objects. Different objects of the same class and static members share the same data.
The following three statements are verified by code:
# include using namespace std;class Base {public: static int val1; / / in-class definition and out-of-class initialization. If the compiler initializes directly, it will report an error int val2;private: static int val3;}; int Base::val1 (1); / / out-of-class initialization, accessing the static member int Base::val3 (2) through the class name / / initialization outside the class. Even private attributes can access the static member int main () {Base base1; Base base2; base1.val1 = 10; base2.val1 = 11; cout through the class name.
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.