jeudi 10 octobre 2019

How to destruct a singleton instance, or why the follow code works for destructor?

the following code used to delete a singleton instance, why the works before delete is necessary?

// @brief Destruct the singleton instance
// @note Only work with gcc/clang
__attribute__((destructor)) static void delete_() {
    //works before delete
    typedef char T_must_be_complete[sizeof(T) == 0 ? -1 : 1];
    (void) sizeof(T_must_be_complete);
    delete instance_;
}

Aucun commentaire:

Enregistrer un commentaire