In java you can do it with
Class.forName("myClass").newInstance();
this will return you a new instance of the class myClass, provided that
you defined it elsewhere. How can I get this in c++ (linux)?
For exemple I'm fetching elements from a vector, they are all
subclasses of a base class Field, but the data type within each
subclass can vary according to a template that was used (exemple
(SubField<int>, Subfield<long>,. Subfield<myclass>, etc..) The objects
were stored/retrieved with the base class pointer Field since they are
taken from a vector
I can still define a common method "void * getData()" in the base class
field but I need to know how to recast once I fetch the values from the
vector if I'm doing some processing with the data.
I'm at least able to store the data name in a member variable, i.e.
SubField<T>: public Field
<template typename T>
setData( T data) {
m_data = data;
m_dataType = typeid(data).name();
}
But once I extract back this object from the vector the string
m_dataType that I can fetch from the Field *object is useless unless I
use a big switch ( I don't like it)
So how can one instanciate an object or define a cast type with only a
string descriptor?