jeudi 25 octobre 2018

why in singleton, check class==null?

    static CMyStatic* myStatic = nullptr;


    CMyStatic* CMyStatic::getInstance(){
        if(myStatic==nullptr)
                myStatic = new CMyStatic;
        return myStatic;
    }

if I make singleton, in getInstance() function,

check class pointer is null. like this code.

I understandiong static object is only making one, isn't it?

then, if i didn't check myStatic==nullptr,

always make myStatic = new CMyStatic,

myStatic isn't making, isn't it?

or my understanding is wrong?

Aucun commentaire:

Enregistrer un commentaire