How to use static data members and static member functions of C++ class
This article mainly shows you "C++ class static data members and static member functions how to use", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "C++ class static data members and static member functions how to use" this article.
Static data member
Declare with the keyword static
When a data member of a class is declared static, no matter how many objects of the class are created, the static member has only one copy.
Shared among all objects of the class, with static lifetime
If there are no other initialization statements, all static data members are initialized to zero when the first object is created
Defined and initialized outside the class, using the range parsing operator (::) to indicate the class to which it belongs
For example:
# include using namespace std;class Box {public: static int count; / / if the static data member is declared in the private section, Box can only be processed through static member functions (double l = 2.0, double b = 2.0, double h = 2.0) {cout