Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use static data members and static member functions of C++ class

Shulou Source: shulou.com Published: 2022-06-03 18:19:05 11月12日 Update

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

Tags: Member static function object data pointer output clocking content total article scope normal case operator learning help private operation key Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information vpn Redmi Xiaomi Shulou Technology