This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: create an object with variable CLASS
Mohsen Pahlevanzadeh wrote:
> Dear Axel,
> I said my means badly,Suppose I have following code:
> module_management::load_module(char *class_name){
> }/////////////////////
> I wanna create an object for each class that it is argument of my
> function.
> same:
> class_name *my_obj = new class_name;
> I can't implement it.
Why not? Make sure that every class has a common superclass and a
static initializer that registers a constructor with a registry.
Then, when you want an instance of class X, call
theRegistry.newClass("X"). theRegistry looks up "X" and creates an
instance of X. theRegistry is just a few lines of C++: it's a map
from string -> constructor.
Andrew.