I am going over a few design patterns C++, and I've come across this error.
class Singleton {
public:
static Singleton* instance;
static Singleton* getInstance() {
if (instance == nullptr) {
instance = new Singleton;
}
return instance;
}
int x;
private:
Singleton() {};
};
Singleton* Singleton::instance = nullptr;
int main()
{
Singleton foo1* = Singleton::getInstance(); // cannot access private member Singleton
}
I am also quite new to the material. Can I get some help in identifying what is wrong / how I can fix this? Also, I am well aware sington designs being 'anti-patterns', this is mostly for practice.