6
Q:

undefined reference to instance

//Put this in the .cpp
Singleton *Singleton::instance = NULL;

//! This is the Singleton definition in .hpp
class Singleton {
private:
  static Singleton *instance;
  
public:
  static Singleton *getInstance() {
    if (instance == NULL) {instance = new Singleton; }
    return instance;
  }

protected:
  Singleton() { std::cout << "singleton created\n"; };
};
1

New to Communities?

Join the community