title: c++ dynamic return type
body: <p>I'm not sure if this is a thing (to be honest I want to say that it is not), but I was wondering if there is a way to write a c++ function so that it can choose which type of object to return.</p>
  
  <p>For example, I have a base class (<code>A</code>) that has 3 child classes (<code>Aa</code>, <code>Ab</code>, <code>Ac</code>). In a factory(<code>F</code>) class I have a <code>std::map&lt;UINT, A*&gt;</code> that holds a number of the child classes based on a <code>UINT id</code>. My goal is to write a function that can build and return the correct object when I pass in an id value.</p>
  
  <p>I'll probably end up returning pointers and cloning the data that they point to, but I was just curious as to whether or not the aforementioned was actually possible.</p>
  
  <p>Thanks!</p>