title: Create class instance based on a string input
body: <p>Background:</p>
  
  <p>In my game engine I have a generic 'script parser' which is used to create game entities by parsing a script file. So in code you would have something like <code>MyEntity* entity = MyScriptParer::Parse("filename.scr");</code></p>
  
  <p>Any class which is to be scriptable inherits from a generic base class. Internally in the game engine there are some specific classes that use this - particles, fonts etc and this all works nicely in the parser - see extract below</p>
  
  <pre><code>std::string line;
  std::getline(ifs, line);
  
  if (line == "[FONT]") {
      CFont* f = new CFont();
      f-&gt;readObject(ifs);
  }
  else if (line == "[PARTICLE]") {
      CParticle* p = new CParticle();
      p-&gt;readObject(ifs);
  }
  ...
  </code></pre>
  
  <p>My problem comes with how to handle user defined classes i.e classes in the games that use the game engine. The base class has an abstract method <code>readObject</code> so anything which inherits must implement this method. </p>
  
  <p>The issue is how would the parser know about the new class? E.g say I have a <code>CVehicle</code> class the parser would now need to know to recognise "[VEHICLE]" and also be able to create a <code>new CVehicle</code></p>
  
  <p>Is there any way to store a class type or something in an array/map so maybe I could have a function to register a list of class types with strings to provide a lookup for creating the new instances?</p>
  
  <p>Bit of a long shot and may not be possible so if anyone has other suggestions on how to approach the parsing they will be welcomed</p>