C++ Variable Type Selection at Runtime
<p>I am upgrading an old application which was written for a specific hardware interface.  I now need to add support for a modern hardware to the existing application.</p>

<p>To do this, I would like to create a class for each hardware type, and assign a variable to one type or the other whenever the user selects which hardware is in their system.</p>

<p>For example:</p>

<p>Class <code>HardwareType1</code> and Class <code>HardwareType2</code> both exist having the same member functions.</p>

<pre><code>object HW;  
if (userHwType = 1)  
    // initialize HW as a HardwareType1 class
}  
else{  
    // initialize HW as a HardwareType2 class  
}
</code></pre>

<p>Now I can use <code>HW.doSomething()</code> throughout my code without a conditional for hardware type every time I interact with the hardware.</p>

<p>I'm sure this is pretty basic but to be honest I don't even know what this is called or what terms to search on for this one.</p>

<p>Thanks!</p>
