mardi 23 mars 2021

Difference beetwen destructors in my class

I'm implementing simplified unique pointer. Everything was pretty clear but I wonder about destructor in class. It should be ~unique_pointer(){obj->~T();} or ~unique_pointer(){delete obj}. I really don't see difference between each other. Can you specify how they work? Below I send whole class

template<class T >class unique_pointer{
private:
T*obj;
public:
unique_pointer(const T* obj):obj{obj}{}
~unique_pointer(){obj->~T();}

T operator*() const { return *obj; }
T* operator->() const { return obj; }

T* release(){T* temp = obj;
    obj = 0;
    return obj;}

}

Aucun commentaire:

Enregistrer un commentaire