delete (this) pointer in destructor
c++
Solution
`this->~destructor` is called, then `delete(this)` will will again call `this->~destructor` thus results in calling function indefinitely.
Problem
I wrote the program just to check what happens if we delete this pointer in the destructor of the classs. Here is my code ``` class xxx{ public: xxx(){cout<<"constructor called"<<endl;} ~xxx(){cout<<"destructor called"<<endl;delete(this);} //deleting the 'this' pointer }; int main(int argc, char *argv[]) { xxx *x1=new xxx(); delete x1; return 0; } ``` When I run this program it results in indefinite loop printing "desctructor called". What is the relation between `delete` operator and destructor function? Also what happens when you use `delete this` in the destructor?