C++: Undefined reference to instance in Singleton-Klasse

Ich bin derzeit versuchen zu implementieren, eine Fabrik als singleton. Ich habe praktisch das lehrbuch-Beispiel des Singleton-Musters. Hier ist die .h-Datei:

namespace oxygen{

class ImpFactory{

public:
    static boost::shared_ptr<ImpFactory> GetInstance();

private:
    static boost::shared_ptr<ImpFactory> mInstance;
};

und hier ist die .cpp-Datei:

#include "impfactory.h"

using namespace oxygen;
using namespace boost;

shared_ptr<ImpFactory> ImpFactory::GetInstance(){
    if (mInstance.get() == 0)
        mInstance = shared_ptr<ImpFactory>(new ImpFactory());
    return mInstance;
}

Den code kompiliert, aber ich bekomme einen linker Fehler:

../../lib/Sauerstoff/liboxygen.so.3.2.4: undefined reference to `Sauerstoff::ImpFactory::mInstance'

Dieser hat derzeit drei Schüler ratlos. Irgendwelche Ideen?

InformationsquelleAutor aheld | 2010-01-27
Schreibe einen Kommentar