Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this -> ~T() do?

Tags:

c++

Can anyone explain what this code extract is doing? My first guess was that d() calls the destructor of itself but then I wondered why you couldn't just call the destructor of T yourself.

class T
{
    void d()
    {
        this -> ~T();
    }
}

Thank you in advance.

like image 827
Ash Burlaczenko Avatar asked Apr 21 '26 21:04

Ash Burlaczenko


1 Answers

That explicitly calls the destructor for T on this. The name of the destructor for T is ~T.

Usually this isn't necessary, as C++ takes care of calling the destructor for an object when it goes out of scope or when you delete it. Without more context it's hard to say what is going on in your code and why the author thought that was necessary.

like image 181
Greg Hewgill Avatar answered Apr 23 '26 11:04

Greg Hewgill