A bug in short c++ code, and I think it's due to the deconstruct function of class. But I cannot find : <p>I think the bug is related to the delete dynamic array manipulation. But I'm not sure in detail.</p>

<p>I'm now studying c++ myself, so I'm a totally freshhand. This is a small exercise from a book and I'm trying to solve it. The "main()" function part is what it originally is so I'm only allowed to code about the class "Array2"</p>

<p>Thanks in advance!   </p>

<pre><code>    #include &lt;iostream&gt;
    #include &lt;cstring&gt;
    using namespace std;
    class Array2
    {
        int row, col;
        int **a;
    public:
        Array2(int s1=1, int s2=1) 
        {
            row = s1;
            col = s2;
            a = new int *[row];
            for (int i = 0; i &lt; row; i++)
            {
                a[i] = new int[col];
            }
        };
        Array2(Array2 &amp; b)
        {
            a = b.a;
        }
        ~Array2()
        {
            for (int i = 0; i &lt; row; i++)
            {   
                    delete[] a[i];
            }

            delete[] a;
        }
        int * operator [] (int i)
        {
            return a[i];
        }
        int operator () (int s1, int s2)
        {
            return a[s1][s2];
        }

    };
    int main() {
        Array2 a(3, 4);
        int i, j;
        for (i = 0; i &lt; 3; ++i)
            for (j = 0; j &lt; 4; j++)
                a[i][j] = i * 4 + j;
        for (i = 0; i &lt; 3; ++i) {
            for (j = 0; j &lt; 4; j++) {
                cout &lt;&lt; a(i, j) &lt;&lt; ",";
            }
            cout &lt;&lt; endl;
        }
        cout &lt;&lt; "next" &lt;&lt; endl;
        Array2 b; b = a;
        for (i = 0; i &lt; 3; ++i) {
            for (j = 0; j &lt; 4; j++) {
                cout &lt;&lt; b[i][j] &lt;&lt; ",";
            }
            cout &lt;&lt; endl;
        }
        return 0;
    }**
</code></pre>
