I'm new and a little ignorant in C++ and I encounter a C++ code that used a singleton pattern,
class CFoo
{
public:
static CFoo& getInstance()
{
static CFoo self;
return self;
}
private:
CFoo(){}
~CFoo(){}
};
I am just confused why return a static reference? Is this a valid code? Why the programmer didn't use a pointer?