I have created several different objects of Dog and Cat inside the container animalColl. I am trying to workout how to adjust the file stream that is read so that if the object in the container is Cat then the catfile is used and Dog uses the dogfile. Currently, only the animalType passed into the parameter is used. Is it possible to choose which file stream is used based on the object type?
void Animal::load(std::string animalType)
{
std::string file = animalType + ".csv";
std::ifstream lstream(file);
for (Animal *a : animalColl)
{
a->load(lstream); //uses one stream to read all the different objects in container
}
}
Aucun commentaire:
Enregistrer un commentaire