static keyword inside a class and outside it

c++, static

Solution

Right.

The keyword `static` is heavily overloaded with too many different meanings:

- On a variable or function at namespace scope it gives the name internal linkage.

- On a class member it makes it a static member, which doesn't affect linkage.

- On a variable at function scope it gives the variable "static storage duration" as opposed to "automatic" or "dynamic" storage duration (i.e. the variable's lifetime extends to the end of the program, like global variables.)

Problem

The static keyword is related to internal linkage generally, but the static keyword used inside a class has external linkage right? The variables m, n below are accessible outside the class file. ``` class c { int i; int j; static int m; static int n; public: void zap(); static void clear(); }; ```

Original source

Related problems