mercredi 6 février 2019

Is there a simpler/better way to do this?

I'm trying to read in some inputs from a file and then pass those to an array of pointers pointing to GasPump objects and this is the only way I've gotten it to work and I'm wondering if there is a simpler way to do it.

inputFile >> thing1 >> thing1 >> thing1 >> thing1
          >> thing2 >> thing2 >> thing2 >> thing2
          >> thing3 >> thing3 >> thing3 >> thing3;
GasPump* station[3] = {new GasPump(thing1, thing1, thing1),
                       new GasPump(thing2, thing2, thing2),
                       new GasPump(thing3, thing3, thing3)};

This is what I had in mind, but I'm not sure if this is even the right track:

GasPump* station = new GasPump[3];
for (int i = 0; i < 3; i++)
{
    intputFile >> thing >> thing >> thing >> thing;
    station[i] = GasPump(thing, thing, thing);
}

Aucun commentaire:

Enregistrer un commentaire