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++?
template <typename T>
class factory
{
T obj;
std::string class_name;
public:
factory(T obj)
{
this->obj = obj;
class_name = boost::typeindex::type_id<T>().pretty_name();
//some magic here
class_name instance;
}
};