How to create Quadtree Copy constructor with Recursion <p>I am working on a copy constructor for a Quadtree. Here's what I have so far:</p> <pre><code> //Copy Constructor Quadtree :: Quadtree(const Quadtree &amp; other) { root = copy(other.root); resolution = other.resolution; } //Copy Constructor helper function Quadtree::QuadtreeNode *Quadtree :: copy (const QuadtreeNode* newRoot) { if (newRoot != NULL) { QuadtreeNode *node = new QuadtreeNode(newRoot-&gt;element); node-&gt;nwChild = copy(newRoot-&gt;nwChild); node-&gt;neChild = copy(newRoot-&gt;neChild); node-&gt;swChild = copy(newRoot-&gt;swChild); node-&gt;seChild = copy(newRoot-&gt;seChild); return node; } else return NULL; } </code></pre> <p>I'm not sure where I am going wrong, but I am receiving memory leaks and Valgrind is pointing out that I have uninitialized values. Help please?</p> <p>Attached, is my buildTree function - where I actually create the tree. I may be doing something wrong here?</p> <pre><code> void Quadtree :: buildTree (PNG const &amp; source, int theResolution) { buildTreeHelp (root, 0, 0, theResolution, source); } void Quadtree :: buildTreeHelp (QuadtreeNode * &amp; newRoot, int xCoord, int yCoord, int d, PNG const &amp; image) { if (d == 1) { RGBAPixel pixel = *image(xCoord, yCoord); newRoot = new QuadtreeNode(pixel); return; } newRoot = new QuadtreeNode (); newRoot = NULL; buildTreeHelp(newRoot-&gt;nwChild, xCoord, yCoord, d/2, image); buildTreeHelp(newRoot-&gt;neChild, xCoord + d/2, yCoord, d/2, image); buildTreeHelp(newRoot-&gt;swChild, d/2, yCoord + d/2, d/2, image); buildTreeHelp(newRoot-&gt;seChild, d/2 + xCoord, d/2 + yCoord, d/2, image); } </code></pre>