| | |
how to insert an object (that holds a vector) into another object
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2008
Posts: 21
Reputation:
Solved Threads: 0
hi,
i was wondering if anyone could help me out with this. i'm getting a compile error like this:
[C++ Error] TestDriver.cpp(26): E2285 Could not find a match for 'Airport::Airport(char *,double,char *,FlightsTL)'
i'm really sorry about this but the code is a bit lengthy. it comprises of two header files and three CPP files (two files that correspond to the header files and one TestDriver). I have to post all of the code so that you can get an understanding of what's happening. basically i'm trying to make the airport have a flight schedule by using the FlightsTL classes objects
next is the corresponding CPP file
here's the next header file
here's the corresp CPP file
and here's the TestDriver
thanks for the help in advance
Jay F
i was wondering if anyone could help me out with this. i'm getting a compile error like this:
[C++ Error] TestDriver.cpp(26): E2285 Could not find a match for 'Airport::Airport(char *,double,char *,FlightsTL)'
i'm really sorry about this but the code is a bit lengthy. it comprises of two header files and three CPP files (two files that correspond to the header files and one TestDriver). I have to post all of the code so that you can get an understanding of what's happening. basically i'm trying to make the airport have a flight schedule by using the FlightsTL classes objects
C++ Syntax (Toggle Plain Text)
#ifndef FLIGHTS_ #define FLIGHTS_ #include <iostream> #include <string> #include <vector> #include <sstream> #include <iterator> using namespace std; class Flight { //a class which makes a flight private: string org; //origin of flight string dest; //destination of flight double depTime; // departure time double dura; // duration of flight public: //Start House-keeping functions /*Default constructor * */ Flight (); /* Constructor for flight object * * */ Flight(const string&, const string&,const double&,const double&); /* copy constructor for flight object * * */ // Flight(const Flight& rhs); /**destructor for flight object * * */ ~Flight(); //end House-keeping functions\\ //_________________Start of other Flight functions___________________________\\ /* Equals operation * */ Flight& operator=(const Flight& rhs); /* get origin * */ string getOrigin()const; /* get destination * */ string getDestination()const; /* get departure time * */ double getDepartureTime()const; /* get duration * */ double getDuration ()const; /* set origin * */ void setOrigin(string); /* set destination * */ void setDestination(string); /* set departure time * */ void setDepartureTime(double); /* get duration * */ void setDuration(double); /* set all * */ void setAll(string,string,double,double); /** ToString to display flight information * */ string toString()const; } ; // _________end of Flight class__________________\\ class FlightsTL{ //container that will hold Flight objects friend class Flight; private: int FlightsNum; // keeps track of how many airports there are vector<Flight> Flights; // container for all flights public: /*Default constructor * */ FlightsTL(); /* constructor * * */ FlightsTL(int); /*copy constructor * * */ FlightsTL (const FlightsTL& rhs); /*destructor * * */ ~FlightsTL(); /*Equals operator * * */ FlightsTL& operator=(const FlightsTL& rhs); /* get FlightsNum * */ int getFlightsNum (); /*is empty function * */ bool isEmpty(); /* set FlightsNum * */ void setFlightsNum(int); /*add a existing Flighr * */ void addFlight(const Flight&); /* * this is adding a new flight */ void addNewFlight(const string&, const string&,const double&, const double&); /** ToString to display flight information * */ string toString(); } ; # endif /*FLIGHTS_*/
next is the corresponding CPP file
C++ Syntax (Toggle Plain Text)
#include"Flights.h" //_____________Start Implementation of Flight class________________\\ /*Start House-keeping functions for Flight Class * Default constructor * */ Flight:: Flight (){ //debug statement cout<< "we are in the construtor with Default arguments\n"; setOrigin(""); setDestination(""); setDepartureTime(0); setDuration(0) ; } /* Constructor for flight object * * */ Flight::Flight(const string &orig ,const string &destin ,const double &dep, const double &dur ){ //debug statement cout<< "we are in the construtor with arguments\n"; setOrigin(orig); setDestination(destin); setDepartureTime(dep); setDuration(dur); } /* copy constructor for flight object * * * FlightsTL:: Flight:: Flight(const Flight& rhs){ } */ /**destructor for flight object * * */ Flight:: ~Flight(){ } //end House-keeping functions \\ //_____________Start other functions____________________________\\ /* Equals operation * */ Flight& Flight::operator=(const Flight& rhs){ return *this; } /* get origin * */ string Flight::getOrigin() const{ return org; } /* get destination * */ string Flight::getDestination()const{ return dest; } /* get departure time * */ double Flight:: getDepartureTime()const{ return depTime; } /* get duration * */ double Flight:: getDuration ()const{ return dura; } /* set origin * */ void Flight:: setOrigin(string t ){ org = t; } /* set destination * */ void Flight:: setDestination(string s){ dest =s; } /* set departure time * */ void Flight:: setDepartureTime(double c){ depTime = c; } /* get duration * */ void Flight:: setDuration(double d){ dura = d; } /* set all * */ void Flight:: setAll(string a,string b,double c,double d){ setOrigin(a); setDestination(b); setDepartureTime(c); setDuration(d) ; } /** ToString to display flight information * */ string Flight:: toString()const{ string s; double depT = getDepartureTime(); double durA = getDuration(); // convert double to string char deptStr[50]; sprintf(deptStr,"%g",depT); // convert to string char durStr[50]; sprintf(durStr,"%g",durA); // print all Flight information s=getOrigin() +"\t"+ getDestination() + "\t"+ deptStr + "\t"+ durStr +"\n" ; return s; } //__________________end of Flight implementation_____________\\ //__________________Start of of FlightsTL implementation_____________\\ /*Default constructor * */ FlightsTL::FlightsTL(){ FlightsNum = 0; } /* constructor * * */ // FlightsTL:: FlightsTL(int num){ // } /*copy constructor * * */ FlightsTL:: FlightsTL (const FlightsTL& rhs){ Flights = rhs.Flights; } /*destructor * * */ FlightsTL:: ~FlightsTL(){ } /*Equals operator * * */ FlightsTL& FlightsTL::operator=(const FlightsTL& rhs){ if (this != &rhs){ return *this; } return *this; } /* get FlightsNum * */ int FlightsTL:: getFlightsNum (){ return FlightsNum; } /* is empty method * */ bool FlightsTL:: isEmpty(){ if(FlightsNum == 0){ return true; } return false; } /* set FlightsNum * */ void FlightsTL:: setFlightsNum(int num){ FlightsNum = num; } void FlightsTL::addFlight(const Flight& Flight){ Flights.push_back(Flight); FlightsNum++; } /*add Flighr * */ void FlightsTL:: addNewFlight(const string& origin , const string& destination,const double& depTime, const double& duration){ Flights.push_back(Flight(origin,destination,depTime,duration)); FlightsNum++; } /** ToString to display all flights and thier information * */ string FlightsTL:: toString(){ vector<Flight>::iterator find; string str; if (getFlightsNum() == 0) { return "Nothing to show" ; } for(find = Flights.begin(); find != Flights.end(); find++){ str+=(*find).toString(); } return str; } //__________________end of FlightsTL Implementation______________\\ //think about adding remove(), and clear() and add via text
here's the next header file
C++ Syntax (Toggle Plain Text)
#ifndef AIRPORTS_ #define AIRPORTS_ #include <iostream> #include <string> #include <vector> #include <sstream> #include <iterator> #include"Flights.h" using namespace std; class Airport { //a class which makes an Airport private: string code; // three letter code for airport double minConnect; //minimum connection time between Flights string description; //a description of airport FlightsTL scheduel; public: //Start House-keeping functions /*Default constructor * */ Airport (); /* Constructor for Airport object * * */ Airport(const string&, const double&, const string&,const Flight& ); /* copy constructor for Airport object * * */ // Airport(const Airport& rhs); /**destructor for Airport object * * */ ~Airport(); //end House-keeping functions\\ //_________________Start of other Airport functions___________________________\\ /* Equals operation * */ Airport& operator=(const Airport& rhs); /* get minimum connection * */ double getMinimumConnectionTime()const; /* get Code * */ string getCode()const; /* get description * */ string getDescription()const; /* * get scheduel * */ FlightsTL getScheduel(); /* * set scheduel * */ void setScheduel(const FlightsTL&); /* set minimum connection time * */ void setMinimumConnect (double); /* set code * */ void setCode (string); /* set description * */ void setDescription (string); /* set all * */ void setAll (string,double,string); /** ToString to display Airport information * */ string toString()const; } ; // _________end of Airport class__________________\\ class AirportsTL{ //container that will hold Airport objects friend class Airport; private: int AirportsNum; // keeps track of how many airports there are vector<Airport> Airports; // container for all Airports public: /*Default constructor * */ AirportsTL(); /* constructor with arguments * * */ AirportsTL(int); /*copy constructor * * */ AirportsTL (const AirportsTL& rhs); /*destructor * * */ ~AirportsTL(); /*Equals operator * * */ AirportsTL& operator=(const AirportsTL& rhs); /* get AirportsNum * */ int getAirportsNum (); /*is empty function * */ bool isEmpty(); /* set AirportsNum * */ void setAirportsNum (int); /*add a existing Flighr * */ void addAirport(const Airport&); /* * this is adding a new Airport */ void addNewAirport(const string&,const double&, const string&); /** ToString to display Airport information * */ string toString(); } ; #endif /*AIRPORTS_*/
here's the corresp CPP file
C++ Syntax (Toggle Plain Text)
#include "Airports.h" //_____________________Start of Airport Class Implementation_________________\\ //Start House-keeping functions /*Default constructor * */ Airport:: Airport (){ setCode(""); setMinimumConnect(0); setDescription(""); setScheduel(FlightsTL plan); } /* Constructor for Airport object * * */ Airport:: Airport(const string& code, const double& minCon, const string& description,const Flight& Fplan){ setCode(code); setMinimumConnect(minCon); setDescription(description); setScheduel(Fplan); } /* copy constructor for Airport object * * */ // Airport(const Airport& rhs); /**destructor for Airport object * * */ Airport:: ~Airport(){ } //end House-keeping functions\\ //_________________Start of other Airport functions___________________________\\ /* Equals operation * */ Airport& Airport:: operator=(const Airport& rhs){ return *this; } /* get minimum connection * */ double Airport:: getMinimumConnectionTime()const{ return minConnect; } /* get Code * */ string Airport:: getCode()const{ return code; } /* get description * */ string Airport:: getDescription()const{ return description; } /* * get scheduel * */ FlightsTL Airport:: getScheduel(){ return scheduel; } /* * set scheduel * */ void Airport::setScheduel(const FlightsTL& s){ scheduel =s; } /* set minimum connection time * */ void Airport:: setMinimumConnect (double a){ minConnect =a; } /* set code * */ void Airport:: setCode (string b){ code = b; } /* set description * */ void Airport:: setDescription (string c){ description = c; } /* set all * */ void Airport:: setAll (string a,double b,string c){ setMinimumConnect(b) ; setCode(a); setDescription(c); } /** ToString to display Airport information * */ string Airport:: toString()const{ string s; double mCon = getMinimumConnectionTime(); // convert double to string char mConStr[50]; sprintf(mConStr,"%g",mCon); // print all Airport information s=getCode() +"\t"+ mConStr + "\t"+ "\t"+ getDescription() +"\n" ; return s; } //____________________end of Airport class implementation___________________\\ //____________________Start of AirportsTL class implementation_______________\\ /*Default constructor * */ AirportsTL:: AirportsTL(){ AirportsNum = 0; } /* constructor with arguments * * */ //AirportsTL:: AirportsTL(int){ //} /*copy constructor * * */ AirportsTL:: AirportsTL (const AirportsTL& rhs){ Airports =rhs.Airports; } /*destructor * * */ AirportsTL:: ~AirportsTL(){ } /*Equals operator * * */ AirportsTL& AirportsTL:: operator=(const AirportsTL& rhs){ if (this != &rhs){ return *this; } return *this; } /* get AirportsNum * */ //------------end of house-keeping------------------\\ int AirportsTL::getAirportsNum (){ return AirportsNum; } /*is empty function * */ bool AirportsTL:: isEmpty(){ if(AirportsNum == 0){ return true; } return false; } /* set AirportsNum * */ void AirportsTL:: setAirportsNum (int a){ AirportsNum = a; } /*add a existing Flighr * */ void AirportsTL:: addAirport(const Airport& Airport){ Airports.push_back(Airport); AirportsNum++; } /* * this is adding a new Airport */ void AirportsTL:: addNewAirport(const string& code,const double& minCon, const string& desc){ Airports.push_back(Airport(code,minCon,desc)); AirportsNum++; } /** ToString to display Airport information * */ string AirportsTL:: toString(){ vector<Airport>::iterator find; string str; if (getAirportsNum() == 0) { return "Nothing to show" ; } for(find = Airports.begin(); find != Airports.end(); find++){ str+=(*find).toString(); } return str; } //____________________end of AirportsTL implementation______________________\\ // remember to ad extra functions remove(), clear() etc
and here's the TestDriver
C++ Syntax (Toggle Plain Text)
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include<iostream> #include"Flights.h" #include "Airports.h" using namespace std; //--------------------------------------------------------------------------- #pragma argsused int main(int argc, char* argv[]){ //Create a Flight object using argumets Flight b ("adl","mel",1.00,1.30); //Create a Flight object using no argumets Flight d; //Create FlightsTL object FlightsTL C; //Attempt to put Flight object into FlightsTL //there is an error when this line is uncommented C.addNewFlight("syd","per",1.00,1.30); C.addFlight(b); //Constructor for airport trying to make it accept a set of flights at the end Airport a("syd",0.30,"Sydney domestic airport",C); //Airport z("Mel",2.30,"Melbourne domestic airport"); AirportsTL j; j.addAirport(a); //j.addAirport(z); //cout<< "TESTING "<< j.toString()<<"\n"; //cout<< "TESTING "<< d.toString()<<"\n"; system("pause"); return 0; } //---------------------------------------------------------------------------
thanks for the help in advance
Jay F
•
•
Join Date: Jan 2008
Posts: 3,829
Reputation:
Solved Threads: 501
I don't see a constructor for this call.
So do you have the above constructor implemented in your code? I didn't see it. If you do not, you cannot make the above call. The closest I see is this:
C is type FlightsTL, not Flight&
Also, you can post your code using C++ style code tags:
[code=cplusplus]
// paste code here
[/code]
This will add line numbers to your code so you can refer to them in the writeup, and say which line the error is coming from. That'll help a lot with code this big.
C++ Syntax (Toggle Plain Text)
Airport a("syd",0.30,"Sydney domestic airport",C);
So do you have the above constructor implemented in your code? I didn't see it. If you do not, you cannot make the above call. The closest I see is this:
C++ Syntax (Toggle Plain Text)
Airport::Airport(const std::string &,const double &,const std::string &,const Flight &)
C is type FlightsTL, not Flight&
Also, you can post your code using C++ style code tags:
[code=cplusplus]
// paste code here
[/code]
This will add line numbers to your code so you can refer to them in the writeup, and say which line the error is coming from. That'll help a lot with code this big.
•
•
Join Date: Jun 2008
Posts: 21
Reputation:
Solved Threads: 0
•
•
•
•
I don't see a constructor for this call.
C++ Syntax (Toggle Plain Text)
Airport a("syd",0.30,"Sydney domestic airport",C);
So do you have the above constructor implemented in your code? I didn't see it. If you do not, you cannot make the above call. The closest I see is this:
C++ Syntax (Toggle Plain Text)
Airport::Airport(const std::string &,const double &,const std::string &,const Flight &)
C is type FlightsTL, not Flight&
Also, you can post your code using C++ style code tags:
[code=cplusplus]
// paste code here
[/code]
This will add line numbers to your code so you can refer to them in the writeup, and say which line the error is coming from. That'll help a lot with code this big.
Thanks for having a look, i will give that a try! and i will use the c++ tags from now on, sorry about that(didn't know)
•
•
Join Date: Nov 2007
Posts: 978
Reputation:
Solved Threads: 208
There is one 'oddity' that needs to be pointed out, namely usage of '\\' as end-of-comment marker. The backslash at the end of the single line comment works as a line continuation character and hence the next line is also taken as comment. You have one instance of this happening, i.e.
So it's better to use something else to end the comment lines.
You have some type mismatches there + something else too
//------------end of house-keeping------------------\\
int AirportsTL::getAirportsNum (){ <- this line turns into a commentSo it's better to use something else to end the comment lines.
You have some type mismatches there + something else too
setScheduel(FlightsTL plan); // maybe you meant just (?) setScheduel(plan); // ---------------------------------- // Fplan is not of type FlightsTL setScheduel(Fplan); // ---------------------------------- // you don't have a ctor taking only 3 arguments Airports.push_back(Airport(code,minCon,desc)); // ---------------------------------- // C is not of type Flight Airport a("syd",0.30,"Sydney domestic airport",C);
•
•
Join Date: Jun 2008
Posts: 21
Reputation:
Solved Threads: 0
you are right in what you said, it compiles now
and it does take the object ie C, but any idea how i would check to see that the C is actually there?
i thought of using airport classes tostring() to do it but have no clue where to start
[code =cpluplus]
string Airport:: toString()const{
string s;
double mCon = getMinimumConnectionTime();
// convert double to string
char mConStr[50];
sprintf(mConStr,"%g",mCon);
// print all Airport information
s=getCode() +"\t"+ mConStr + "\t"+ getDescription() + "\n" ;
return s;
} [/code]
thanks again for answering previous question
and it does take the object ie C, but any idea how i would check to see that the C is actually there?
i thought of using airport classes tostring() to do it but have no clue where to start
[code =cpluplus]
string Airport:: toString()const{
string s;
double mCon = getMinimumConnectionTime();
// convert double to string
char mConStr[50];
sprintf(mConStr,"%g",mCon);
// print all Airport information
s=getCode() +"\t"+ mConStr + "\t"+ getDescription() + "\n" ;
return s;
} [/code]
thanks again for answering previous question
•
•
Join Date: Jan 2008
Posts: 3,829
Reputation:
Solved Threads: 501
•
•
•
•
you are right in what you said, it compiles now
and it does take the object ie C, but any idea how i would check to see that the C is actually there?
i thought of using airport classes tostring() to do it but have no clue where to start
[code =cpluplus]
string Airport:: toString()const{
string s;
double mCon = getMinimumConnectionTime();
// convert double to string
char mConStr[50];
sprintf(mConStr,"%g",mCon);
// print all Airport information
s=getCode() +"\t"+ mConStr + "\t"+ getDescription() + "\n" ;
return s;
} [/code]
thanks again for answering previous question
I don't understand what you are asking here in red. You were close on the code tags, but you had a space in there and you forgot an s:
[code =cpluplus]
You don't want the space. You want it like this:
[code=cplusplus]
•
•
Join Date: Jun 2008
Posts: 21
Reputation:
Solved Threads: 0
•
•
•
•
I don't understand what you are asking here in red. You were close on the code tags, but you had a space in there and you forgot an s:
[code =cpluplus]
You don't want the space. You want it like this:
[code=cplusplus]
I was refering to the C object i created in the TestDriver
C++ Syntax (Toggle Plain Text)
FlightsTL C; //Attempt to put Flight object into FlightsTL //there is an error when this line is uncommented C.addNewFlight("syd","per",1.00,1.30); C.addFlight(b); //Constructor for airport trying to make it accept a set of flights at the end Airport a("syd",0.30,"Sydney domestic airport",C);
I need to know how to print out each Flight's detail (from C), i am thinking of writing a Fuction like this
C++ Syntax (Toggle Plain Text)
/* * print all Flights */ string Airport:: PrintFlights(){ getScheduel(); }
then calling that PrintFlights() in my toString for Airport class. But dont know how to implement the PrintFlights function.
Last edited by 007tron; Jun 14th, 2008 at 5:48 am. Reason: spelling
•
•
Join Date: Jan 2008
Posts: 3,829
Reputation:
Solved Threads: 501
•
•
•
•
I was refering to the C object i created in the TestDriver
C++ Syntax (Toggle Plain Text)
FlightsTL C; //Attempt to put Flight object into FlightsTL //there is an error when this line is uncommented C.addNewFlight("syd","per",1.00,1.30); C.addFlight(b); //Constructor for airport trying to make it accept a set of flights at the end Airport a("syd",0.30,"Sydney domestic airport",C);
I need to know how to print out each Flight's detail (from C), i am thinking of writing a Fuction like this
C++ Syntax (Toggle Plain Text)
/* * print all Flights */ string Airport:: PrintFlights(){ getScheduel(); }
then calling that PrintFlights() in my toString for Airport class. But dont know how to implement the PrintFlights function.
Well, Airport has a data member called "scheduel", which is of type FlightsTL. FlightsTL has a data member which is a vector of type Flight called Flights. Do you have an Airport:: PrintFlight() function? If so, I would traverse the Flights vector and make a call to that function for each Flight in the Flights vector:
C++ Syntax (Toggle Plain Text)
string Airport:: PrintFlights() { for (int i = 0; i < scheduel.Flights.size(); i++) { Flight aFlight = scheduel.Flights.at(i); aFlight.PrintFlight(); } }
Is that what you have in mind? If these data members are private, you may need to use a public accessor function in lines 3 and 5.
![]() |
Other Threads in the C++ Forum
- Previous Thread: URGENT help needed with strings.
- Next Thread: Needing someone really nice to look at my code
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






