Analysis of the static keyword in C ++

1. Global static variables

. a life cycle: the entire program
. b Scope: The current file
. c Initialization: uninitialized -> automatically initialized to 0

2. Local static variables

. a life cycle: the entire program
. b scope: the current code segment
. c Initialization: Uninitialized -> automatically initialized to 0 (only once)

3. Static ordinary function

Scope: Current file -> file with the same name does not conflict with other functions

4. Static class members

. A do not belong: Sharing -> belongs to the class, all the shared data objects, this pointer is not
b call: all members of the class

The class static function

. a case of do: Sharing -> only belong to the class, all objects in shared data, no this pointer
b calls: only call static class members.
c access method: static class name :: function name.

Released seven original articles · won praise 1 · views 28

Guess you like

Origin blog.csdn.net/weixin_45793136/article/details/105124955