title: C++ Array of pointers to class names
body: <p>I'd like to be able to hold an array of class names and simply pass an index to a function which would create an instance of a certain class. I have memory constraints so I'd like to not simply create an array of objects.</p>
  
  <p>Here's my most descriptive pseudo-code:</p>
  
  <p>Classes:</p>
  
  <pre><code>class Shape
  {
  public:
      Shape();
  };
  
  class Square : public Shape
  {
  public:
      Square();
  };
  
  class Triangle : public Shape
  {
  public:
      Triangle();
  };
  </code></pre>
  
  <p>Main:</p>
  
  <pre><code>int main()
  {
      pointerToShapeClass arrayOfShapes[2];       // incorrect syntax - but
      arrayOfShapes[0] = pointerToSquareClass;    // how would i do this?
      arrayOfShapes[1] = pointerToTriangleClass;
  
      cin &lt;&lt; myNumber;
  
      // Depending on input, create instance of class corresponding to array index
      if (myNumber == 0) { // create Square   instance }
      if (myNumber == 1) { // create Triangle instance }
  
      return 0;
  }
  </code></pre>
  
  <p>If this is confusing, I can try to elucidate. Thanks in advance!</p>
  
  <p>Edit:</p>
  
  <p>Really, I think I just need a pointer to a class without actually instantiating the class.</p>