lundi 8 février 2016

Undefined reference to Singleton::Singleton() [duplicate]

I'm trying to get the first basic singleton example from Design Patterns working, but this has me stumped.

This code compiles cleanly with g++ -c Singleton.cpp:

class Singleton {
public:
    static Singleton* Instance();
protected:
    Singleton();
private:
    static Singleton* _instance;
};

Singleton* Singleton::_instance = 0;

Singleton* Singleton::Instance() {
    if (_instance == 0) {
        _instance = new Singleton;
    }
    return _instance;
}

But when I add a skeletal main() and compile with g++ Singleton.cpp I get undefined reference to 'Singleton::Singleton()'.

What am I missing?

Aucun commentaire:

Enregistrer un commentaire