I am trying to create an array of Object pointers in order to sort some data. Here is my code:
ArrayClass<Exoplanet*> exoplanets;
int count = 0;
for (int i = 0; i < exosystems.size(); ++i) {
ArrayClass<Exoplanet> *temp = exosystems.at(i)->getPlanets();
for (int k = 0; k < temp->size(); ++k) {
exoplanets.add(&temp->at(k));
}
temp->~ArrayClass();
}
//check to see if pointer array is working properly
for (int i = 0; i < exoplanets.size(); ++i) {
exoplanets.at(i)->printPlanet();
cout << endl;
}
ArrayClass<Exoplanet> *Exosystem::getPlanets(void) const
{
return planets;
}
Also the getPlanets() function is included at the end for reference. Whenever I print the planets in the last for loop, all of the exoplanet pointers point to the last exoplanet returned from the getPlanet() function the final time through the 1st for loop. I think this has something to do with exoplanets.add(&temp->at(k)), but I am not sure how to fix it. Thanks in advance