mercredi 27 avril 2016

Singleton class crashes

Iv'e implemented a singleton class that looks something like this:

h file:

class MySingleton
{
public:
    static MySingleton& GetInstance();

private:
    MySingleton();
    virtual ~MySingleton();

    std::map<MyStruct, PointerToClass*, MyCompareStruct> mMyMap;
    CRITICAL_SECTION mMyMapCriticalSection;
};

cpp file:

MySingleton& MySingleton::GetInstance()
{
    static MySingleton instance;

    return instance;
}

On some runs my code crashes on the instance initialization:

    static MySingleton instance;

Am I doing something wrong in my implementation? I'm working on visual studio 2015

Aucun commentaire:

Enregistrer un commentaire