In C# an object can be created based on knowledge of the desired type like this (among a few other ways)
public T GetInstance<T>(string type)
{
return (T)Activator.CreateInstance(Type.GetType(type));
}
Is there an equivalent way of doing this in native c++?
I have a base
class and a derived
class. I wish to construct the proper object based on stored data. I have control over what this stored data is, but I need to know what information needs to be stored to identify the type and then how to use that data to later call a constructor.
I'm essentially looking for the c++ answer to this question: Dynamically create an object of <Type>