title: Behavior of delete this pointer in C++
body: <p>I am trying to explore this pointer in c++ .
  I have created a pointer to class object and caling a function to delete the current object but the behavior is unexpected.</p>
  
  <p>Why output of the last print statement is 
  x= 0 , y= 6. </p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  class Test
  {
  private:
    int x;
    int y;
  public:
    Test(int x = 6, int y = 6) { this-&gt;x = x; this-&gt;y = y; }
    void setX(int a) { x = a; }
    void setY(int b) { y = b; }
    void destroy()  { delete this; 
   }
    void print() { cout &lt;&lt; "x = " &lt;&lt; x &lt;&lt; " y = " &lt;&lt; y &lt;&lt; endl; }
  };
  
  int main()
  { 
    Test *obj = new Test();
    Test objs;
    obj-&gt;print();
    obj-&gt;destroy();
  
    obj-&gt;print();
    return 0;
  }
  </code></pre>