Const and static are orthogonal concepts in both C and C ++.
The const keyword tells the compiler to prevent the variable from being displayed as the lvalue of any expression - essentially making it read-only.
In C, the static has several uses, depending on what it applies to. When applied to a variable of a function, it indicates that the variable is not stored in the local scope of the function, but is accessible through its calls. When applied to a global variable or function, it becomes available only for a specific file - in other words, it is available only inside the compilation unit (unless extern declared).
In C ++, the static can be used in a class definition to make a variable or function shared in all instances of the class, rather than being local to each instance. In addition, the static function of a class in C ++ can access only the static variables of this class (or the classes to which it has access). Now in C ++ const it gives members an internal binding to the compilation module, if they are not explicitly declared extern - this may be what you refer to it. This allows you to share compile-time constants through a unit through the use of header files. Keep in mind, however, that members are not very static - rather, the constant is compiled into every place it refers to.
LBushkin Jun 15 '09 at 21:32 2009-06-15 21:32
source share