0

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;
    }
};
4

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.