How to delete this 2D Array in C++
<p>I've absolutely no idea why my delete codes inside the destructor won't be able to functionally well. I hope u guys can help me for this. </p>

<p>Thank you so much!</p>

<pre><code>class Array2D
{
      public: 
      Array2D();
      Array2D(int,  int);
      ~Array2D();

      private:
      int row;
      int col;
      int **p;
};

Array2D::Array2D()
{
      // Default Constructor
}


Array2D::Array2D(int rows, int cols)
{
     this -&gt; row = rows;
     this -&gt; col = cols;

     p = new int* [row]; 
     for(int i=0; i&lt; row; i++)
          p[i] = new int[col];

     // Fill the 2D array
     for (int i = 0; i &lt; row; i++)
          for (int j = 0; j &lt; col; j++)
          {
               p[i][j] = rand () % 100;
          }
}    


Array2D::~Array2D()
{
     // I'm using this way to delete my 2D array.
     // however, it won't work!

     for (int i = 0; i &lt; row; i++)
     {
          delete[]p[i];
     }
     delete[]p;
}
</code></pre>
