Hey guys,
I have a problem printing out the contents of a list of objects, with the following code I loop through the list and call the displayInfo() method that it's responsible for printing out the different attributes of the object.
I have tested the displayInfo() method and works fine, however when I'm calling the method when looping through the list I don't gwt the right content.
Please thake a look at the following code and let me know if you see anything wrong.
void displayAircrafts(list <Aircraft>& detectedAircrafts)
{
cout << " DISPLAYING ENTRIES \n";
cout << " ================== \n";
cout << "There are " << detectedAircrafts.size()<< " aircrafts in the list!\n\n";
/*loop through the list by using the iterator*/
list <Aircraft>::const_iterator iAircraft;
for (iAircraft= detectedAircrafts.begin(); iAircraft != detectedAircrafts.end(); ++iAircraft)
{
Aircraft temp = *iAircraft;
temp.displayInfo();
}
}
And this is how I add objects in the list, note that this is part of the code. My actual code compiles fine:
newAir=addAircraft(&dummy);
aircrafts.push_back(newAir);
displayAircrafts(aircrafts);
When I try to display the contents stored in the newAir object by calling the displayInfo method (i.e. newAir.displayInfo()) I get the right result, while the displayAircrafts method gives me something that memory addresses and most of the fields are empty.
Thanks in advance,
Liza