mercredi 30 janvier 2019

How to make and class array to define what class use to next instance?

I usually works with python and I keep the mind of this language. So I want to make an array or struct like that:

struct instanceType = {
std::string name,
class typeOfclass
};

The idea is to run a loop to check from a string list a match with instanceType and get from this the class for instance a new object. e.g.

instanceType type1;
type1.name = "Type1";
type1.class = Class1;
instanceType type2;
type1.name = "Type2";
type1.class = Class2;
int implementTypes = 2;
instanceType typesArray[implementTypes] = {type1, type2};

// This is the goal I want
...
for(int i=0; i < implementTypes; ++i) {
    for(const std::string& objectToCreate; objectsToCreate) {
        if(typesArray[i].name==objectToCreate) {
            typesArray[i].class newObject = typesArray[i]() //"Constructor"
        }
    }
}

It could be crazy but it would be very useful to be able to use something similar.

Aucun commentaire:

Enregistrer un commentaire