Test.h
class Test
{
public:
Test();
//some methods
private:
int var;
//some vars
}
Test.cpp
#include "Test.h"
int a;
void func()
{
//some code here
}
Test::Test()
{
//some code
}
Variable a and function func() are non-member and non-static.
What is the lifetime of variable a and function func()?
Consider Test class as a part of a shared library. Can other classes of that library access a or func() by resolution operator ?
What is difference between static declaration of variable a/ func() and nonstatic declaration of a/func() ?
The MSDN page is the answer to your question. It defines scope and Lifetime.
ahave scope and life time through out the file since its global.func()doesnt have scope or lifetime. they only have visibility.if its part of shared library also functions and global variables can be accessed by other parts provided library is visible.
In this case being static doesnt make much of a difference. But local variables when made static gets global scope but will have only local visibility.