title: Good way to create class object instance according to a string value in c++?
body: <p>See the code snip for the question:</p>
  <pre><code>class Base; 
  typedef Base* BasePtr; 
  
  template&lt;typename D&gt;
  BasePtr CreateDerivedClass() {
      return new D();
  }
  
  class D1 : public Base {
  ....
  };
  
  class D2 : public Base {
  ....
  }
  
  void main() {
      std::string derived_name = {&quot;D1&quot;, &quot;D2&quot;}; 
      std::vector&lt;BasePtr&gt; derived_vec; 
      for (auto&amp; name : derived_name) {
  // QUESTION: Other than factory design pattern, how can I pass the derived 
  // class typename which is the value of string &quot;name&quot; to CreateDerivedClass&lt;name&gt; ?
          derived_vec.push_back(CreateDerivedClass&lt;name&gt;()); 
      }
  }
  </code></pre>
  <p>Note: Here, I don't want to use the factory design pattern which required the derived class register itself during definition.</p>