Reputation: 2470
I totally understand the use of static functions that are members of a class. But what might be the probable use of static functions that are not related to any class or defined globally. eg-
#include <iostream>
using namespace std;
static int func()
{
cout<<"This is a function";
}
int main()
{
/*Random code here*/
return 0;
}
Upvotes: 1
Views: 64
Reputation: 490138
This creates a function that's visible only inside that translation unit. A translation unit is basically that source file (after preprocessing, so what was in the headers it included plus what's directly in the file itself).
It's roughly equivalent to putting the function inside an anonymous namespace, but the anonymous namespace is generally considered preferable.
Upvotes: 4