Can we make a non-member function static?

In C++,Can we make a non-member function as static?If yes,then in which situation should we make such kind of functions?How do they work?What will be the relevance to make these functions?
If you mean something like this:
1
2
3
4
static void foo()
{
  // ...
}

It means that the function is only visible in the file where it was declared. It means that you can't call it from another cpp file, and that you can have several static functions named foo() in several source files.

This is a common way to add internal helper functions that are used internally in a source file. However, using the static keyword is kind of old-fashioned, because in C++ you can use an unnamed namespace to achieve the same effect:

1
2
3
4
5
namespace {
void foo()
{
}
}

Topic archived. No new replies allowed.