dimanche 1 mai 2016

C++ array of object constructors

I have several classes named Child1, Child2 ... etc, inherited from object Parent. I need to create an object by its name, for example if I have string "Child1", I need to create object Child1 and so on.

I thought about something like:

struct registry_entry {
    const char* name;
    IREGISTRY* (*initializer)(); 
};

struct registry_entry registry_list[] =
{
    {"xml", &REGISTRY_XML::REGISTRY_XML},
}

But I can't get address of object constructor.I believe that this problem must be already solved, and the solution is pretty simple, but I can't find it.

Aucun commentaire:

Enregistrer un commentaire