title: I need to organize my classes in a way that the constructor can be called from a loop
body: <p>This is going to be hard to explain so let me use an example:</p>
  
  <p>Imagine you have 10 items on a GUI that are all inheriting members from the same abstract base class. You want to be able to use a loop to check if the user clicked on any of the items. Then you want to be able to call a constructor from that item. The essence of this is that pointers point to objects but I am asking if It is possible to have them point to the actual class or do something with a similar function. Seeing as this explanation could seem a little bit confusing allow me to elaborate with code.</p>
  
  <p>This example will use 3 Items rather than 10 for simplicity</p>
  
  <pre><code>class A //the base class
  {
  public:
      int x,y;// inherited values
      virtual void render() = 0;// thats right its an abstract class
  };
  A * basePointer = NULL;
  
  
  class a0: public A
  {
  public:
      a0()
      {
          //do stuff
      }
      void render()
      {
          //do render stuff
      }
  }
  
  class a1: public A
  {
  public:
      a1()
      {
          //do different stuff
      }
      void render()
      {
          //do different render stuff
      }
  }
  
  class a2: public A
  {
  public:
      a2()
      {
          //do even more stuff
      }
      void render()
      {
          //do even more render stuff
      }
  }
  
  
  
  mainloop()
  {
      //handle events and get mouse position
      for(int i = 0;i &lt; 3;i++)//3 being the number of non-absract classes
      {
          if(a[i].x = mousePos.x &amp;&amp; a[i].y = mousePos.y)
          {
              basePointer = new a[i]
          }
      }
  }
  </code></pre>
  
  <p>I understand that trying to reference a1,a2, and a3 using a[i] and a loop was kind of silly but I hope It helps you understand what I am trying to do. Any help help or work around suggestions is appreciated.</p>