jeudi 1 mars 2018

Create Instance of Object by Classname in C++

i'm looking for a solution of my actual problem. Lets say, i have something like a header file named Module with some virtual methods and i have some specific implementations Module1, Module2, ..., ModuleN based on Module.

I dont really know which one of these modules i will create an instance when i start the program, the user decides with an program argument -module ModuleK which one he wants to start. So, how can i create an instance of my ModuleK only with the class name? I need something like javas classloader, is there something like that in c++ ? I saw some solutions where i regist those objects :

Instantiate class from name?

and i would like do it more dynamic, not hard-coded. The user "repl" already described how could it work, but is there another option?





Aucun commentaire:

Enregistrer un commentaire