How to make a deep copy?
<p>So basically let's say I have 2 classes now. 1 is called Human and the other one is called House.</p>

<p>What I have done now is made that the house makes and destroys human, so basically in the House .h file I have</p>

<pre><code>    Human *humanP;
</code></pre>

<p>And in the .cpp files constructor</p>

<pre><code>    humanP = new Human;
    humanP-&gt;something(); // lets me access the methods in the Human class
</code></pre>

<p>As far as I know this makes a composition and House creates/destroys the Human object. But I need to add parameters to my Human object like height and age for example.</p>

<p>In the main I want to have something like</p>

<pre><code>int age, height;

cout &lt;&lt; "Whats your age? &lt;&lt; endl;
cin &gt;&gt; age;
cout &lt;&lt; "Whats your height? &lt;&lt; endl;
cin &gt;&gt; height;
</code></pre>

<p>With this I want to make</p>

<pre><code>Human humanO(age, height);
</code></pre>

<p>Which will create Human object with those parameters. But I still want the Human object to be held in House class and then destroyed there. As far as I know I need to make a deep copy of that, so that I can copy the humanO inside the House class and then delete the object in the main file.</p>

<p>I've been looking trough examples but there are quite a lot of different ones, could anyone write what the code would look like to make a deep copy of this Human object that is created in main?</p>

<p>Edit:</p>

<p>Making an edit here instead of replying cause it's easier to write code here.</p>

<p>Okay another stupid question. If I use the simple method with</p>

<pre><code>Human *newPerson = new Human
</code></pre>

<p>and do</p>

<pre><code>House house;
house.addHuman(newPerson)
</code></pre>

<p>while having the class method</p>

<pre><code>addHuman(Human *other)
{
   this-&gt;humanP = other;
   cout &lt;&lt; humanP-&gt;getAge() &lt;&lt; endl &lt;&lt; endl &lt;&lt; endl;
}
</code></pre>

<p>it works fine and gives me the age.</p>

<p>If I use smart pointers it doesn't work, what should I change? It gives me errors like "no matching function". What arguments should I put into the <code>addHuman()</code> so that it would take the smart pointer thingy?</p>