Static variables and static functions in c++

References: Static member functions and static members

1. Static variables:

1. Static variables belong to the variables of the class, are shared by the class, and the memory is allocated during compilation.

2. Static variables are declared in the header file (like global variables, do not define static variables in the header file), and are defined in the .cpp file.

3. Static variables can be used by non-static functions.

Second, the static function:

Since a static function does not contain the this pointer of the class, a non-static member function of a class cannot be called.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324879228&siteId=291194637