Author Topic:   What are static variables???
Steve van Bennekom
New Member
posted October 31, 1999 03:25 AM         
With VC++ 5.0 i got a thin book about programming.. It said something about static variables.. I didn't understand it ...
So what ARE static variables?

Thanks in advance
Steve van Bennekom

[This message has been edited by Steve van Bennekom (edited October 31, 1999).]


New Member
posted October 31, 1999 01:12 PM            

first there's three types of static variables.
Global static variables, local static variables and member static variables.

Global static variables are variables that are accessible at file scope only. So if you use many files (.cpp for instance), only the one that have the definition will be able to use it even if it is global to the program.

local static variables are variables that aren't destroyed when the function exit. So when the function is called again, it keeps the value of the static variable.

member static variable is a variable that is defined in a class. It is accessible by all the functions plus the static functions. All the instances of the class access exactly the same variable. (only one copy is kept for all the instances)

There's is also static functions. Static functions are only accessible at the file scope, and static member functions are functions that cannot access member variables of the class, only the static ones.

Hope it helps!