title: memory deallocation problem of an object
body: <p>I hava a class</p>
  
  <pre><code>class vlarray {
  public:
      double *p;
      int size;
  
      vlarray(int n) {
          p = new double[n];
          size = n;
          for(int i = 0; i &lt; n; i++)
              p[i] = 0.01*i;
      }
  
      ~vlarray() {
          cout &lt;&lt; "destruction" &lt;&lt; endl;
          delete [] p;
          size = 0;
      }
  };
  </code></pre>
  
  <p>when I use in main </p>
  
  <pre><code>int main() {
      vlarray a(3);
      {
          vlarray b(3);
          b.p[0] = 10;
          for(int i = 0; i &lt; 3; i++) {
              cout &lt;&lt; *(b.p+i) &lt;&lt; endl;
          }
          a = b;
      }    // the magic happens here deallocation of b
      for(int i = 0; i &lt; 3; i++) {
          cout &lt;&lt; *(a.p+i) &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>when b deallocated smth happens to a .. what is the problem, why that problem occurs and how to avoid such type of problems?</p>