title: Can we create an object using a string holding class name in C++?
body: <p>In the below example, I extract the class name from the template type T. Now I want to use this string to create an instance of a class. Is there a way to achieve it in C++?</p>
  <pre><code>template &lt;typename T&gt;
  class factory
  {
      T obj;
      std::string class_name;
  public:
      factory(T obj)
      {
          this-&gt;obj = obj;
  
          class_name = boost::typeindex::type_id&lt;T&gt;().pretty_name();
          
          //some magic here
          class_name instance;
      }
  };
  </code></pre>