-1

I've been doing some experimenting with function libraries and namespaces. I noticed that you can declare a function in a namespace as static, although it is not within a class declaration:

hpp:

ANameSpace
{

    static void aFunc();

};

cpp:

ANameSpace
{

    static void aFunc()
    {
        std::cout<<"Static function called"<<std::endl;
    }

};

I understand the concept of static class members and how they can be very useful, but are there any particular advantages to using static outside a class?

Note: I cast the final vote to close this question (can't delete because there is an answer) because the reference cited as dup, although it is much broader in scope, contains a detailed discussion of static. But I'm not sure if it exactly answers the question as I have rephrased it now.

Vector
  • 10,879
  • 12
  • 61
  • 101

1 Answers1

2

A static global function is visible only in the scope of the file. This is probably due to C compatibility, where this was also possible.

This sums up every possible use of static pretty well.

Community
  • 1
  • 1
Theolodis
  • 4,977
  • 3
  • 34
  • 53