title: Using new operator for copy an object to heap without knowing its type
body: <p>I have a doubt, the function below can receive an object of type A or something derived type.</p>
  
  <pre><code>A *copyToHeap(A &amp;obj) {
      A *ptr=new A(obj);
      return ptr;
  }
  </code></pre>
  
  <p>If we call it like this:</p>
  
  <pre><code>//B inherits from A
  B bObj;
  B *hPtr=copyToHeap(bObj);
  </code></pre>
  
  <p>The object pointed by <code>hPtr</code> is actually of type A or B?
  Is safe doing this?</p>