what does a static function do?

Hey everyone,

So I've seen examples in source code, etc, where a function's return type is declared as static, such as

static int foobar();

or something along those lines. Would anyone mind telling me what that does? I looked for examples in the tutorial and couldn't find anything. Thank you!
I'm pretty sure 'static' means non-changing, or cannot be changed.

But I am not sure what use it would give to a function.
CheesyBeefy is confusing static with const.
The static keyword is used to store a variable only once
eg:
1
2
3
4
for (int i=0; i<5; i++)
{
    static int n=0;
}

Instead of creating each time a new int called 'n' is used the one previously declared with its old value (this is useful for memory saving).
This is talking about variables but I don't know why a function should be declared static.
a static function is defined to create scope and persistance. A static function is declared within a class, but may be declared outside the class also. The function exists prior to the class and persists.
A static function inside a class is a function that can be called without an instance of the class.

A static function at file/namespace scope (ie, not within a class) within a .cpp file is a function whose symbol is not exported in the .o; that is, the function is not visible outside that .cpp file.

I assume the example in the original post is the latter case.
Topic archived. No new replies allowed.