Static in C++
Two basic meanings
Static Storage
--allocated once at a fixed address
Visibility of a name
--internal linkage
Don‘t use static except inside functions and classes.
Uses of "static" in C++
Static free functions----deprecated弃用
Static globle variables----deprecated弃用
Static local variables----Persistent storage持久存储
Static member variables----Shared by all instances所有对象共享
Static member functions----Shared by all instances, can only access static member variables所有对象共享,只能访问静态变量或静态函数
Static inside functions
Value is remembered for entire program
Initialization occurs only once
时间: 2024-10-27 07:21:43