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.