| | |
Problem with std::list
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: May 2009
Posts: 20
Reputation:
Solved Threads: 0
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.
And this is how I add objects in the list, note that this is part of the code. My actual code compiles fine:
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
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.
c++ Syntax (Toggle Plain Text)
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(); } }
c++ Syntax (Toggle Plain Text)
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
•
•
Join Date: May 2009
Posts: 20
Reputation:
Solved Threads: 0
I've been looking to this problem for a while but I'm sure that it is something really stupid but I can't find what it is.
Here's the aircraft.cpp file:
Here's the aircraft.cpp file:
c++ Syntax (Toggle Plain Text)
#include "aircraft.h" Aircraft::Aircraft() { longitude=""; latitude=""; altitude=""; country=""; flight=""; code=""; earliestTime=""; latestTime=""; isOnGround=true; speed=0.0; track=0.0; verticalRate=0.0; } Aircraft::Aircraft(string& newLongitude, string& newLatitude, string& newAltitude,string& newCountry, string& newFlight, string& newCode, string& newEarliestTime, string& newLatestTime, bool& newBool, double& newSpeed, double& newTrack, double& newRate) { longitude=newLongitude; latitude=newLatitude; altitude=newAltitude; country=newCountry; flight=newFlight; code=newCode; earliestTime=newEarliestTime; latestTime=newLatestTime; isOnGround= newBool; speed= newSpeed; track= newTrack; verticalRate= newRate; } Aircraft::Aircraft(string newLongitude, string newLatitude, string newAltitude, string newCountry, string newFlight, string newCode, string newEarliestTime, string newLatestTime, bool newBool, double newSpeed, double newTrack, double newRate) { longitude=newLongitude; latitude=newLatitude; altitude=newAltitude; country=newCountry; flight=newFlight; code=newCode; earliestTime=newEarliestTime; latestTime=newLatestTime; isOnGround= newBool; speed= newSpeed; track= newTrack; verticalRate= newRate; } void Aircraft::setAll(string newLongitude, string newLatitude, string newAltitude, string newCountry, string newFlight, string newCode, string newEarliestTime, string newLatestTime, bool newBool, double newSpeed, double newTrack, double newRate) { longitude=newLongitude; latitude=newLatitude; altitude=newAltitude; country=newCountry; flight=newFlight; code=newCode; earliestTime=newEarliestTime; latestTime=newLatestTime; isOnGround= newBool; speed= newSpeed; track= newTrack; verticalRate= newRate; } Aircraft::Aircraft(const Aircraft& orig) { } Aircraft::~Aircraft() { } //set methods void Aircraft::setCoords(string newLong, string newLat, string newAlt ) { longitude= newLong; latitude= newLat; altitude= newAlt; } void Aircraft::setEarliestTime(string newTime)//the time that the aircraft was first detected { earliestTime=newTime; } void Aircraft::setLatestTime(string newTime) { latestTime = newTime; } void Aircraft::setCode(string newCode)//this is the uniques aircraft ID, column 3 in the bst file { code=newCode; } void Aircraft::setFlight(string newFlight)// column 5 { flight = newFlight; } void Aircraft::setCountry(string newCountry)//column 6 { country=newCountry; } void Aircraft::setLong(string newLong) //column 11 in the bst file { longitude = newLong; } void Aircraft::setLat(string newLat) // column 10 in the bst file { latitude = newLat; } void Aircraft::setAlt(string newAlt) // column 8 and 9 in the bst file (in feet) { altitude= newAlt; } void Aircraft::setIsOnGround(bool newBool) { isOnGround=newBool; } void Aircraft::setTrack(double newTrack) { track=newTrack; } void Aircraft::setSpeed(double newSpeed) { speed=newSpeed; } void Aircraft::setVerticalRate(double newRate) { verticalRate=newRate; } //get methods string Aircraft::getCode() { return code; } string Aircraft::getFlight() { return flight; } string Aircraft::getCountry() { return country; } string Aircraft::getLong() { return longitude; } string Aircraft::getLat() { return latitude; } string Aircraft::getAlt() { return altitude; } string Aircraft::getEarliestTime() { return earliestTime; } string Aircraft::getLatestTime() { return latestTime; } bool Aircraft::getIsOnGround() { return isOnGround; } double Aircraft::getTrack() { return track; } double Aircraft::getSpeed() { return speed; } double Aircraft::getVerticalRate() { return verticalRate; } /* OPERATIONS */ void Aircraft::displayInfo() { std::cout << "Displaying Aircraft Information\n"; std::cout << "-------------------------------\n"; std::cout << "Longitude:\t" << longitude << "\n"; std::cout << "Latitude:\t" << latitude << "\n"; std::cout << "Altitude:\t" << altitude << "\n"; std::cout << "Country:\t" << country << "\n"; std::cout << "Callsign:\t" << flight << "\n"; std::cout << "ModeS add:\t" << code << "\n"; std::cout << "Earliest Time:\t" << earliestTime << "\n"; std::cout << "Latest Time:\t" << latestTime << "\n"; std::cout << "Landed:\t\t" << isOnGround << "\n"; std::cout << "Speed:\t\t" << speed << "\n"; std::cout << "Track:\t\t" << track << "\n"; std::cout << "Vertical Rate:\t" << verticalRate << "\n"; std::cout << "\n\n\n"; }
![]() |
Similar Threads
- [newbie] problem with structs in a list (C++)
- Error in std::list ? (C++)
- problem about linked list. (C++)
- problem for dropdown list inrepeator conrtrol (JavaScript / DHTML / AJAX)
- BIG problem with STL List Container (C)
- Weird (?) problem using std::list ... (C++)
Other Threads in the C++ Forum
- Previous Thread: Is there a library with DOS system commands?
- Next Thread: mscache
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






