title: C++ 11 Template Variable Design
body: <p>I have a lot of subclasses of an abstract class Letter, like A, B, C, D, etc.  Letter has an integer ID variable, and every subclass of Letter gets assigned a unique id.  </p>
  
  <p>I then have another class, call it Alphabet.  Alphabet has an </p>
  
  <pre><code>list&lt;shared_ptr&lt;Letter&gt;&gt; 
  </code></pre>
  
  <p>member.  Here is the problem... I would like to elegantly add B's and C's or other subclasses of Letter to particular instances of Alphabets.  I think the most convenient way to do this would be to use the integer id of subclass somehow.  In other words, I want to be able to have something like Alphabet.addLetter(int id), so if I did alphabet1.add(14), it would somehow add a shared_ptr for class H to the list.  </p>
  
  <p>Is there an elegant way to do this, avoiding some huge if statement where that I need to constantly update every time I add or remove one of the B, C, D, E, etc. classes?  I'm hoping there's some kind of template-solution, but I'm not very familiar with advanced c++ notions like factories and templates.  The naive thing I wanted was some kind of vector/map that converted my ids into class names, so that I could do something like </p>
  
  <pre><code>list.push_back(shared_ptr&lt;classVector(i)&gt;(new classVector(i))
  </code></pre>
  
  <p>or something like that, though I have no idea if that's possible.  </p>
  
  <p>Thanks!</p>
  
  <p>p.s. I just chose the Alphabet example because I didn't want to give unnecessary detail.  Obviously I'm not trying to design alphabets in such a silly way, lol. </p>
  
  <p>edit: I'm struggling to make this make sense.  My goal is to be able to create new subclasses of Letter very quickly with minimal effort.  I would like to avoid having to type out code that looks like...</p>
  
  <pre><code>list.push_back(shared_ptr&lt;X&gt;(...));
  </code></pre>
  
  <p>every time I make a new letter.  Does this make sense at all?</p>