How do you create a copy constructor of pointers to objects (deep copy)?
<p>How do you create deep copy of dynamic array of pointers to objects? I believe in this code, I'm only allocating new memory for the pointers to objects, but they still pointed on the same location. Therefore, when I change the "copied" image, the original image is also changed, and vice versa.</p>

<p>Thanks!</p>

<p>declatration:</p>

<pre><code>Class Scene
{
public: 
    .
    .
    .
    .
private:
    Image ** sceneImage;
    int * coordinateX;
    int * coordinateY;
    int inputMax;
};
</code></pre>

<p>in copy constructor...</p>

<pre><code> Scene::Scene (const Scene &amp; source)
 {
    inputMax = source.inputMax;
    sceneImage = new Image*[inputMax];
    coordinateX = new int[inputMax];
    coordinateY = new int[inputMax];

    // copy even null indexes, because you can put images on null indexes
    for (int i = 0; i &lt; inputMax; i++)
    {
        sceneImage[i] = source.SceneImage[i];
        coordinateX[i] = source.coordinateX[i];
        coordinateY[i] = source.coordinateY[i];
    }
}
</code></pre>
