I'm learning about Singleton design pattern. I have the following code example:
//singleton.hpp
#ifndef SINGLETON_HPP
#define SINGLETON_HPP
class Singleton {
public:
static Singleton& Instance();
private:
Singleton();
static Singleton* instance_;
};
#endif
and:
//singleton.cpp
#include "singleton.hpp"
Singleton* Singleton::instance_ = 0;
Singleton& Singleton::Instance() {
if (instance_ == 0) {
instance_ = new Singleton();
}
return *instance_;
}
Singleton::Singleton() {
}
What I don't understand is the line:
Singleton* Singleton::instance_ = 0;
What does this line do and how? I have never seen something like this.