I l@ve RuBoard Previous Section Next Section

14.6 The Meaning of static

The keyword static has many different meanings in C++. Table 14-1 is a complete list of the various ways static can be used.

Table 14-1. The meanings of static

Usage

Meaning

Variable outside the body of any function

The scope of the variable is limited to the file in which it is declared.

Variable declaration inside a function

The variable is permanent. It is initialized once, and only one copy is created even if the function is called recursively.

Function declaration

The scope of the function is limited to the file in which it is declared.

Member variable

One copy of the variable is created per class (not one per object).

Member function

Function can only access static members of the class.

    I l@ve RuBoard Previous Section Next Section