I have two classes, Date and Flight. In my Flight object I have Two date objects. I'm running into trouble when trying to initialize the Dates. My current code is below. I don't understand why what I'm doing doesn't work. The flight header file has a #include "Date.h" command, so by including the flight header, i include the date header, right? The errors say:

Flight.cpp: In constructor `Flight::Flight()':
Flight.cpp:7: error: no match for call to `(Date) (int, int, int)'
Flight.cpp:8: error: no match for call to `(Date) (int, int, int)'
Flight.cpp: In constructor `Flight::Flight(int, std::string, std::string, Date, Date)':
Flight.cpp:18: error: no match for call to `(Date) (int&, int&, int&)'
Flight.cpp:19: error: no match for call to `(Date) (int&, int&, int&)'

#include "Flight.h"

Flight::Flight() {
   flightNum = 0;
   origin = " ";
   dest = " ";
   dep(1,1,2000);
   ret(1,1,2000);
}

Flight::Flight(int fNum, string _origin, string _dest, Date _dep, Date _ret) {
   int d1 = _dep.day(), m1 = _dep.month(), y1 = _dep.year();
   int d2 = _ret.day(), m2 = _ret.month(), y2 = _ret.year();

   flightNum = fNum;
   origin = _origin;
   dest = _dest;
   dep(d1, m1, y1);
   ret(d2, m2, y2);
}

>dep(1,1,2000);
>ret(1,1,2000);
This is assuming that your Date class overloads the function call operator and allows three arguments. I'm guessing you don't have that particular overload, in which case what you were trying to do (initialize dep and ret to new instances of the Date class using a three parameter constructor) uses this syntax:

dep = Date(1,1,2000);
ret = Date(1,1,2000);

Likewise further down:

dep = Date(d1, m1, y1);
ret = Date(d2, m2, y2);

Thank you, I think that'll help. In the initializer, could I just set the two Dates equal to each other?

Like this:

dep = _dep;
ret = _ret;

>In the initializer, could I just set the two Dates equal to each other?
Without seeing the class definition for Date, I can't say for sure, but I can imagine how it's implemented and be fairly confident that you can do that and it'll work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.