I am reading someone else's code. It consists of:
class foo
{
public:
/*
* Other functions
*/
void BeginSession() { /* some code */ }
void EndSession() { /* some code */ }
static foo& Get()
{
static foo instance;
return instance;
}
};
int main()
{
foo::Get().BeginSession();
function_a();
foo::Get().EndSession();
}
What is the purpose of the following piece of code? Because it seems to me that it creates an instance of foo
and then makes it usable inside function_a()
.
static foo& Get()
{
static foo instance;
return instance;
}
Thank you in advance for taking the time to answer this. I know my title is a bit silly, but if you could rephrase it better, please be my guest.