dimanche 30 octobre 2016

C++ singleton in constructor

Is this possible?

class A {
    static A *instance = NULL;

public:
    A () {
        if (instance) {
            this = instance;
        } else {
            instance = this;
        }
    }
}

Does it have leak memory?

Do I need to oveload new operator?

Aucun commentaire:

Enregistrer un commentaire