how to insert an object (that holds a vector) into another object

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2008
Posts: 21
Reputation: 007tron is an unknown quantity at this point 
Solved Threads: 0
007tron 007tron is offline Offline
Newbie Poster

how to insert an object (that holds a vector) into another object

 
0
  #1
Jun 14th, 2008
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

  1.  
  2.  
  3.  
  4. #ifndef FLIGHTS_
  5. #define FLIGHTS_
  6. #include <iostream>
  7. #include <string>
  8. #include <vector>
  9. #include <sstream>
  10. #include <iterator>
  11. using namespace std;
  12.  
  13. class Flight { //a class which makes a flight
  14.  
  15. private:
  16. string org; //origin of flight
  17. string dest; //destination of flight
  18. double depTime; // departure time
  19. double dura; // duration of flight
  20.  
  21.  
  22. public:
  23. //Start House-keeping functions
  24. /*Default constructor
  25. *
  26. */
  27. Flight ();
  28.  
  29. /* Constructor for flight object
  30. *
  31. *
  32. */
  33. Flight(const string&, const string&,const double&,const double&);
  34.  
  35. /* copy constructor for flight object
  36. *
  37. *
  38. */
  39.  
  40. // Flight(const Flight& rhs);
  41.  
  42. /**destructor for flight object
  43. *
  44. *
  45. */
  46. ~Flight();
  47.  
  48. //end House-keeping functions\\
  49.  
  50. //_________________Start of other Flight functions___________________________\\
  51.  
  52. /* Equals operation
  53. *
  54. */
  55. Flight& operator=(const Flight& rhs);
  56.  
  57. /* get origin
  58. *
  59. */
  60. string getOrigin()const;
  61.  
  62. /* get destination
  63. *
  64. */
  65. string getDestination()const;
  66.  
  67. /* get departure time
  68. *
  69. */
  70. double getDepartureTime()const;
  71.  
  72. /* get duration
  73. *
  74. */
  75. double getDuration ()const;
  76.  
  77. /* set origin
  78. *
  79. */
  80. void setOrigin(string);
  81.  
  82. /* set destination
  83. *
  84. */
  85. void setDestination(string);
  86.  
  87. /* set departure time
  88. *
  89. */
  90. void setDepartureTime(double);
  91.  
  92. /* get duration
  93. *
  94. */
  95. void setDuration(double);
  96.  
  97. /* set all
  98. *
  99. */
  100.  
  101. void setAll(string,string,double,double);
  102.  
  103. /** ToString to display flight information
  104. *
  105. */
  106. string toString()const;
  107.  
  108.  
  109. } ;
  110.  
  111.  
  112.  
  113. // _________end of Flight class__________________\\
  114.  
  115.  
  116.  
  117.  
  118. class FlightsTL{ //container that will hold Flight objects
  119.  
  120.  
  121. friend class Flight;
  122.  
  123. private:
  124. int FlightsNum; // keeps track of how many airports there are
  125. vector<Flight> Flights; // container for all flights
  126.  
  127. public:
  128.  
  129.  
  130. /*Default constructor
  131. *
  132. */
  133. FlightsTL();
  134.  
  135. /* constructor
  136. *
  137. *
  138. */
  139.  
  140. FlightsTL(int);
  141.  
  142. /*copy constructor
  143. *
  144. *
  145. */
  146.  
  147. FlightsTL (const FlightsTL& rhs);
  148.  
  149. /*destructor
  150. *
  151. *
  152. */
  153. ~FlightsTL();
  154.  
  155. /*Equals operator
  156. *
  157. *
  158. */
  159. FlightsTL& operator=(const FlightsTL& rhs);
  160.  
  161. /* get FlightsNum
  162. *
  163. */
  164. int getFlightsNum ();
  165.  
  166. /*is empty function
  167. *
  168. */
  169. bool isEmpty();
  170. /* set FlightsNum
  171. *
  172. */
  173. void setFlightsNum(int);
  174.  
  175. /*add a existing Flighr
  176. *
  177. */
  178. void addFlight(const Flight&);
  179.  
  180. /*
  181. * this is adding a new flight
  182. */
  183. void addNewFlight(const string&, const string&,const double&, const double&);
  184.  
  185. /** ToString to display flight information
  186. *
  187. */
  188. string toString();
  189.  
  190.  
  191. } ;
  192. # endif /*FLIGHTS_*/

next is the corresponding CPP file

  1. #include"Flights.h"
  2.  
  3. //_____________Start Implementation of Flight class________________\\
  4.  
  5.  
  6. /*Start House-keeping functions for Flight Class
  7. * Default constructor
  8. *
  9. */
  10. Flight:: Flight (){
  11. //debug statement
  12. cout<< "we are in the construtor with Default arguments\n";
  13.  
  14. setOrigin("");
  15. setDestination("");
  16. setDepartureTime(0);
  17. setDuration(0) ;
  18.  
  19.  
  20. }
  21.  
  22. /* Constructor for flight object
  23. *
  24. *
  25. */
  26. Flight::Flight(const string &orig ,const string &destin ,const double &dep, const double &dur ){
  27. //debug statement
  28. cout<< "we are in the construtor with arguments\n";
  29.  
  30. setOrigin(orig);
  31. setDestination(destin);
  32. setDepartureTime(dep);
  33. setDuration(dur);
  34.  
  35.  
  36.  
  37. }
  38.  
  39. /* copy constructor for flight object
  40. *
  41. *
  42. *
  43.  
  44. FlightsTL:: Flight:: Flight(const Flight& rhs){
  45.  
  46.  
  47.  
  48. } */
  49.  
  50. /**destructor for flight object
  51. *
  52. *
  53. */
  54. Flight:: ~Flight(){
  55.  
  56. }
  57. //end House-keeping functions \\
  58.  
  59.  
  60. //_____________Start other functions____________________________\\
  61.  
  62. /* Equals operation
  63. *
  64. */
  65. Flight& Flight::operator=(const Flight& rhs){
  66.  
  67. return *this;
  68. }
  69.  
  70. /* get origin
  71. *
  72. */
  73. string Flight::getOrigin() const{
  74.  
  75. return org;
  76. }
  77.  
  78. /* get destination
  79. *
  80. */
  81. string Flight::getDestination()const{
  82.  
  83. return dest;
  84.  
  85. }
  86.  
  87. /* get departure time
  88. *
  89. */
  90. double Flight:: getDepartureTime()const{
  91.  
  92. return depTime;
  93.  
  94. }
  95.  
  96. /* get duration
  97. *
  98. */
  99. double Flight:: getDuration ()const{
  100.  
  101. return dura;
  102.  
  103. }
  104.  
  105. /* set origin
  106. *
  107. */
  108. void Flight:: setOrigin(string t ){
  109.  
  110. org = t;
  111. }
  112.  
  113. /* set destination
  114. *
  115. */
  116. void Flight:: setDestination(string s){
  117.  
  118. dest =s;
  119.  
  120. }
  121.  
  122. /* set departure time
  123. *
  124. */
  125. void Flight:: setDepartureTime(double c){
  126.  
  127. depTime = c;
  128. }
  129.  
  130. /* get duration
  131. *
  132. */
  133. void Flight:: setDuration(double d){
  134.  
  135. dura = d;
  136. }
  137.  
  138. /* set all
  139. *
  140. */
  141.  
  142. void Flight:: setAll(string a,string b,double c,double d){
  143.  
  144. setOrigin(a);
  145. setDestination(b);
  146. setDepartureTime(c);
  147. setDuration(d) ;
  148. }
  149.  
  150. /** ToString to display flight information
  151. *
  152. */
  153. string Flight:: toString()const{
  154. string s;
  155. double depT = getDepartureTime();
  156. double durA = getDuration();
  157. // convert double to string
  158. char deptStr[50];
  159. sprintf(deptStr,"%g",depT);
  160. // convert to string
  161. char durStr[50];
  162. sprintf(durStr,"%g",durA);
  163. // print all Flight information
  164. s=getOrigin() +"\t"+ getDestination() + "\t"+ deptStr + "\t"+ durStr +"\n" ;
  165. return s;
  166. }
  167.  
  168.  
  169. //__________________end of Flight implementation_____________\\
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176. //__________________Start of of FlightsTL implementation_____________\\
  177.  
  178. /*Default constructor
  179. *
  180. */
  181. FlightsTL::FlightsTL(){
  182.  
  183. FlightsNum = 0;
  184.  
  185. }
  186.  
  187. /* constructor
  188. *
  189. *
  190. */
  191.  
  192. // FlightsTL:: FlightsTL(int num){
  193.  
  194.  
  195.  
  196. // }
  197.  
  198. /*copy constructor
  199. *
  200. *
  201. */
  202.  
  203. FlightsTL:: FlightsTL (const FlightsTL& rhs){
  204. Flights = rhs.Flights;
  205.  
  206.  
  207. }
  208.  
  209. /*destructor
  210. *
  211. *
  212. */
  213. FlightsTL:: ~FlightsTL(){
  214.  
  215.  
  216. }
  217.  
  218. /*Equals operator
  219. *
  220. *
  221. */
  222. FlightsTL& FlightsTL::operator=(const FlightsTL& rhs){
  223. if (this != &rhs){
  224. return *this;
  225. }
  226.  
  227. return *this;
  228. }
  229.  
  230. /* get FlightsNum
  231. *
  232. */
  233. int FlightsTL:: getFlightsNum (){
  234.  
  235. return FlightsNum;
  236.  
  237. }
  238. /* is empty method
  239. *
  240. */
  241. bool FlightsTL:: isEmpty(){
  242.  
  243. if(FlightsNum == 0){
  244. return true;
  245.  
  246. }
  247. return false;
  248.  
  249. }
  250.  
  251. /* set FlightsNum
  252. *
  253. */
  254. void FlightsTL:: setFlightsNum(int num){
  255.  
  256. FlightsNum = num;
  257.  
  258. }
  259.  
  260. void FlightsTL::addFlight(const Flight& Flight){
  261.  
  262. Flights.push_back(Flight);
  263. FlightsNum++;
  264.  
  265. }
  266.  
  267.  
  268. /*add Flighr
  269. *
  270. */
  271. void FlightsTL:: addNewFlight(const string& origin , const string& destination,const double& depTime, const double& duration){
  272.  
  273. Flights.push_back(Flight(origin,destination,depTime,duration));
  274. FlightsNum++;
  275.  
  276. }
  277.  
  278. /** ToString to display all flights and thier information
  279. *
  280. */
  281. string FlightsTL:: toString(){
  282. vector<Flight>::iterator find;
  283. string str;
  284.  
  285. if (getFlightsNum() == 0) {
  286. return "Nothing to show" ;
  287. }
  288.  
  289. for(find = Flights.begin(); find != Flights.end(); find++){
  290. str+=(*find).toString();
  291.  
  292. }
  293. return str;
  294.  
  295. }
  296.  
  297.  
  298. //__________________end of FlightsTL Implementation______________\\
  299.  
  300.  
  301.  
  302.  
  303. //think about adding remove(), and clear() and add via text


here's the next header file

  1.  
  2. #ifndef AIRPORTS_
  3. #define AIRPORTS_
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7. #include <sstream>
  8. #include <iterator>
  9. #include"Flights.h"
  10. using namespace std;
  11.  
  12. class Airport { //a class which makes an Airport
  13.  
  14. private:
  15.  
  16. string code; // three letter code for airport
  17. double minConnect; //minimum connection time between Flights
  18. string description; //a description of airport
  19. FlightsTL scheduel;
  20.  
  21.  
  22. public:
  23. //Start House-keeping functions
  24. /*Default constructor
  25. *
  26. */
  27. Airport ();
  28.  
  29. /* Constructor for Airport object
  30. *
  31. *
  32. */
  33. Airport(const string&, const double&, const string&,const Flight& );
  34.  
  35. /* copy constructor for Airport object
  36. *
  37. *
  38. */
  39.  
  40. // Airport(const Airport& rhs);
  41.  
  42. /**destructor for Airport object
  43. *
  44. *
  45. */
  46. ~Airport();
  47.  
  48. //end House-keeping functions\\
  49.  
  50. //_________________Start of other Airport functions___________________________\\
  51.  
  52. /* Equals operation
  53. *
  54. */
  55. Airport& operator=(const Airport& rhs);
  56.  
  57. /* get minimum connection
  58. *
  59. */
  60. double getMinimumConnectionTime()const;
  61.  
  62. /* get Code
  63. *
  64. */
  65. string getCode()const;
  66.  
  67. /* get description
  68. *
  69. */
  70. string getDescription()const;
  71.  
  72.  
  73. /*
  74. * get scheduel
  75. *
  76. */
  77. FlightsTL getScheduel();
  78.  
  79.  
  80. /*
  81. * set scheduel
  82. *
  83. */
  84. void setScheduel(const FlightsTL&);
  85.  
  86.  
  87. /* set minimum connection time
  88. *
  89. */
  90. void setMinimumConnect (double);
  91.  
  92. /* set code
  93. *
  94. */
  95. void setCode (string);
  96.  
  97. /* set description
  98. *
  99. */
  100. void setDescription (string);
  101.  
  102.  
  103.  
  104. /* set all
  105. *
  106. */
  107.  
  108. void setAll (string,double,string);
  109.  
  110. /** ToString to display Airport information
  111. *
  112. */
  113. string toString()const;
  114.  
  115.  
  116. } ;
  117.  
  118.  
  119.  
  120. // _________end of Airport class__________________\\
  121.  
  122.  
  123.  
  124.  
  125. class AirportsTL{ //container that will hold Airport objects
  126.  
  127.  
  128. friend class Airport;
  129.  
  130. private:
  131. int AirportsNum; // keeps track of how many airports there are
  132. vector<Airport> Airports; // container for all Airports
  133.  
  134. public:
  135.  
  136.  
  137. /*Default constructor
  138. *
  139. */
  140. AirportsTL();
  141.  
  142. /* constructor with arguments
  143. *
  144. *
  145. */
  146.  
  147. AirportsTL(int);
  148.  
  149. /*copy constructor
  150. *
  151. *
  152. */
  153.  
  154. AirportsTL (const AirportsTL& rhs);
  155.  
  156. /*destructor
  157. *
  158. *
  159. */
  160. ~AirportsTL();
  161.  
  162. /*Equals operator
  163. *
  164. *
  165. */
  166. AirportsTL& operator=(const AirportsTL& rhs);
  167.  
  168. /* get AirportsNum
  169. *
  170. */
  171. int getAirportsNum ();
  172.  
  173. /*is empty function
  174. *
  175. */
  176. bool isEmpty();
  177. /* set AirportsNum
  178. *
  179. */
  180. void setAirportsNum (int);
  181.  
  182. /*add a existing Flighr
  183. *
  184. */
  185. void addAirport(const Airport&);
  186.  
  187. /*
  188. * this is adding a new Airport
  189. */
  190. void addNewAirport(const string&,const double&, const string&);
  191.  
  192. /** ToString to display Airport information
  193. *
  194. */
  195. string toString();
  196.  
  197.  
  198. } ;
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207. #endif /*AIRPORTS_*/

here's the corresp CPP file

  1. #include "Airports.h"
  2.  
  3. //_____________________Start of Airport Class Implementation_________________\\
  4.  
  5.  
  6.  
  7. //Start House-keeping functions
  8. /*Default constructor
  9. *
  10. */
  11. Airport:: Airport (){
  12. setCode("");
  13. setMinimumConnect(0);
  14. setDescription("");
  15. setScheduel(FlightsTL plan);
  16.  
  17. }
  18.  
  19. /* Constructor for Airport object
  20. *
  21. *
  22. */
  23. Airport:: Airport(const string& code, const double& minCon, const string& description,const Flight& Fplan){
  24. setCode(code);
  25. setMinimumConnect(minCon);
  26. setDescription(description);
  27. setScheduel(Fplan);
  28.  
  29.  
  30. }
  31.  
  32. /* copy constructor for Airport object
  33. *
  34. *
  35. */
  36.  
  37. // Airport(const Airport& rhs);
  38.  
  39. /**destructor for Airport object
  40. *
  41. *
  42. */
  43. Airport:: ~Airport(){
  44.  
  45.  
  46.  
  47. }
  48.  
  49. //end House-keeping functions\\
  50.  
  51. //_________________Start of other Airport functions___________________________\\
  52.  
  53. /* Equals operation
  54. *
  55. */
  56. Airport& Airport:: operator=(const Airport& rhs){
  57.  
  58. return *this;
  59.  
  60. }
  61.  
  62. /* get minimum connection
  63. *
  64. */
  65. double Airport:: getMinimumConnectionTime()const{
  66.  
  67. return minConnect;
  68.  
  69. }
  70.  
  71. /* get Code
  72. *
  73. */
  74. string Airport:: getCode()const{
  75. return code;
  76.  
  77.  
  78. }
  79.  
  80. /* get description
  81. *
  82. */
  83. string Airport:: getDescription()const{
  84.  
  85.  
  86. return description;
  87.  
  88.  
  89. }
  90.  
  91. /*
  92. * get scheduel
  93. *
  94. */
  95. FlightsTL Airport:: getScheduel(){
  96.  
  97. return scheduel;
  98.  
  99. }
  100.  
  101.  
  102. /*
  103. * set scheduel
  104. *
  105. */
  106. void Airport::setScheduel(const FlightsTL& s){
  107. scheduel =s;
  108.  
  109.  
  110. }
  111.  
  112.  
  113.  
  114.  
  115. /* set minimum connection time
  116. *
  117. */
  118. void Airport:: setMinimumConnect (double a){
  119.  
  120. minConnect =a;
  121.  
  122. }
  123.  
  124. /* set code
  125. *
  126. */
  127. void Airport:: setCode (string b){
  128. code = b;
  129.  
  130.  
  131. }
  132.  
  133. /* set description
  134. *
  135. */
  136. void Airport:: setDescription (string c){
  137.  
  138. description = c;
  139.  
  140. }
  141.  
  142.  
  143.  
  144. /* set all
  145. *
  146. */
  147.  
  148. void Airport:: setAll (string a,double b,string c){
  149.  
  150. setMinimumConnect(b) ;
  151. setCode(a);
  152. setDescription(c);
  153.  
  154.  
  155. }
  156.  
  157. /** ToString to display Airport information
  158. *
  159. */
  160. string Airport:: toString()const{
  161.  
  162. string s;
  163. double mCon = getMinimumConnectionTime();
  164.  
  165. // convert double to string
  166. char mConStr[50];
  167. sprintf(mConStr,"%g",mCon);
  168.  
  169. // print all Airport information
  170. s=getCode() +"\t"+ mConStr + "\t"+ "\t"+ getDescription() +"\n" ;
  171. return s;
  172.  
  173. }
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183. //____________________end of Airport class implementation___________________\\
  184.  
  185. //____________________Start of AirportsTL class implementation_______________\\
  186.  
  187.  
  188.  
  189. /*Default constructor
  190. *
  191. */
  192. AirportsTL:: AirportsTL(){
  193.  
  194. AirportsNum = 0;
  195.  
  196. }
  197.  
  198. /* constructor with arguments
  199. *
  200. *
  201. */
  202.  
  203. //AirportsTL:: AirportsTL(int){
  204.  
  205.  
  206.  
  207. //}
  208.  
  209. /*copy constructor
  210. *
  211. *
  212. */
  213.  
  214. AirportsTL:: AirportsTL (const AirportsTL& rhs){
  215. Airports =rhs.Airports;
  216.  
  217.  
  218. }
  219.  
  220. /*destructor
  221. *
  222. *
  223. */
  224. AirportsTL:: ~AirportsTL(){
  225.  
  226.  
  227.  
  228. }
  229.  
  230. /*Equals operator
  231. *
  232. *
  233. */
  234. AirportsTL& AirportsTL:: operator=(const AirportsTL& rhs){
  235.  
  236. if (this != &rhs){
  237. return *this;
  238. }
  239.  
  240. return *this;
  241.  
  242.  
  243. }
  244.  
  245. /* get AirportsNum
  246. *
  247. */
  248.  
  249. //------------end of house-keeping------------------\\
  250. int AirportsTL::getAirportsNum (){
  251.  
  252. return AirportsNum;
  253.  
  254.  
  255. }
  256.  
  257. /*is empty function
  258. *
  259. */
  260. bool AirportsTL:: isEmpty(){
  261. if(AirportsNum == 0){
  262. return true;
  263.  
  264. }
  265. return false;
  266.  
  267. }
  268. /* set AirportsNum
  269. *
  270. */
  271. void AirportsTL:: setAirportsNum (int a){
  272.  
  273. AirportsNum = a;
  274.  
  275. }
  276.  
  277. /*add a existing Flighr
  278. *
  279. */
  280. void AirportsTL:: addAirport(const Airport& Airport){
  281.  
  282.  
  283. Airports.push_back(Airport);
  284. AirportsNum++;
  285.  
  286. }
  287.  
  288. /*
  289. * this is adding a new Airport
  290. */
  291. void AirportsTL:: addNewAirport(const string& code,const double& minCon, const string& desc){
  292.  
  293. Airports.push_back(Airport(code,minCon,desc));
  294. AirportsNum++;
  295.  
  296. }
  297.  
  298. /** ToString to display Airport information
  299. *
  300. */
  301. string AirportsTL:: toString(){
  302.  
  303. vector<Airport>::iterator find;
  304. string str;
  305.  
  306. if (getAirportsNum() == 0) {
  307. return "Nothing to show" ;
  308. }
  309.  
  310. for(find = Airports.begin(); find != Airports.end(); find++){
  311. str+=(*find).toString();
  312.  
  313. }
  314. return str;
  315.  
  316. }
  317.  
  318.  
  319.  
  320.  
  321. //____________________end of AirportsTL implementation______________________\\
  322.  
  323.  
  324.  
  325. // remember to ad extra functions remove(), clear() etc

and here's the TestDriver

  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include<iostream>
  6. #include"Flights.h"
  7. #include "Airports.h"
  8. using namespace std;
  9.  
  10. //---------------------------------------------------------------------------
  11.  
  12. #pragma argsused
  13. int main(int argc, char* argv[]){
  14. //Create a Flight object using argumets
  15. Flight b ("adl","mel",1.00,1.30);
  16. //Create a Flight object using no argumets
  17. Flight d;
  18. //Create FlightsTL object
  19. FlightsTL C;
  20. //Attempt to put Flight object into FlightsTL
  21. //there is an error when this line is uncommented
  22. C.addNewFlight("syd","per",1.00,1.30);
  23. C.addFlight(b);
  24. //Constructor for airport trying to make it accept a set of flights at the end
  25.  
  26. Airport a("syd",0.30,"Sydney domestic airport",C);
  27. //Airport z("Mel",2.30,"Melbourne domestic airport");
  28. AirportsTL j;
  29. j.addAirport(a);
  30. //j.addAirport(z);
  31.  
  32.  
  33. //cout<< "TESTING "<< j.toString()<<"\n";
  34.  
  35. //cout<< "TESTING "<< d.toString()<<"\n";
  36.  
  37. system("pause");
  38. return 0;
  39. }
  40. //---------------------------------------------------------------------------


thanks for the help in advance

Jay F
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 21
Reputation: 007tron is an unknown quantity at this point 
Solved Threads: 0
007tron 007tron is offline Offline
Newbie Poster

Re: how to insert an object (that holds a vector) into another object

 
0
  #2
Jun 14th, 2008
Anyone got anything?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,829
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: how to insert an object (that holds a vector) into another object

 
0
  #3
Jun 14th, 2008
I don't see a constructor for this call.

  1. 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:

  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 21
Reputation: 007tron is an unknown quantity at this point 
Solved Threads: 0
007tron 007tron is offline Offline
Newbie Poster

Re: how to insert an object (that holds a vector) into another object

 
0
  #4
Jun 14th, 2008
Originally Posted by VernonDozier View Post
I don't see a constructor for this call.

  1. 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:

  1. 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)
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 978
Reputation: mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice 
Solved Threads: 208
mitrmkar mitrmkar is offline Offline
Posting Shark

Re: how to insert an object (that holds a vector) into another object

 
0
  #5
Jun 14th, 2008
Originally Posted by 007tron View Post
Anyone got anything?
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.
//------------end of house-keeping------------------\\
		   int AirportsTL::getAirportsNum (){ <- this line turns into a comment

So 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);
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 21
Reputation: 007tron is an unknown quantity at this point 
Solved Threads: 0
007tron 007tron is offline Offline
Newbie Poster

Re: how to insert an object (that holds a vector) into another object

 
0
  #6
Jun 14th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 21
Reputation: 007tron is an unknown quantity at this point 
Solved Threads: 0
007tron 007tron is offline Offline
Newbie Poster

Re: how to insert an object (that holds a vector) into another object

 
0
  #7
Jun 14th, 2008
got it!! :p thanks
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,829
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: how to insert an object (that holds a vector) into another object

 
0
  #8
Jun 14th, 2008
Originally Posted by 007tron View Post
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]
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 21
Reputation: 007tron is an unknown quantity at this point 
Solved Threads: 0
007tron 007tron is offline Offline
Newbie Poster

Re: how to insert an object (that holds a vector) into another object

 
0
  #9
Jun 14th, 2008
Originally Posted by VernonDozier View Post
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
  1. FlightsTL C;
  2. //Attempt to put Flight object into FlightsTL
  3. //there is an error when this line is uncommented
  4. C.addNewFlight("syd","per",1.00,1.30);
  5. C.addFlight(b);
  6. //Constructor for airport trying to make it accept a set of flights at the end
  7.  
  8. 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

  1.  
  2. /*
  3. * print all Flights
  4. */
  5. string Airport:: PrintFlights(){
  6.  
  7.  
  8. getScheduel();
  9.  
  10.  
  11.  
  12.  
  13. }

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
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,829
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: how to insert an object (that holds a vector) into another object

 
0
  #10
Jun 14th, 2008
Originally Posted by 007tron View Post
I was refering to the C object i created in the TestDriver
  1. FlightsTL C;
  2. //Attempt to put Flight object into FlightsTL
  3. //there is an error when this line is uncommented
  4. C.addNewFlight("syd","per",1.00,1.30);
  5. C.addFlight(b);
  6. //Constructor for airport trying to make it accept a set of flights at the end
  7.  
  8. 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

  1.  
  2. /*
  3. * print all Flights
  4. */
  5. string Airport:: PrintFlights(){
  6.  
  7.  
  8. getScheduel();
  9.  
  10.  
  11.  
  12.  
  13. }

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:

  1. string Airport:: PrintFlights()
  2. {
  3. for (int i = 0; i < scheduel.Flights.size(); i++)
  4. {
  5. Flight aFlight = scheduel.Flights.at(i);
  6. aFlight.PrintFlight();
  7. }
  8. }

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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC