So I've seen examples in source code, etc, where a function's return type is declared as static, such as
staticint 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!
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++)
{
staticint 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.