I’m working a program where there’s an Airline class. The Airline class contains a vairable to an array of dynamic Flight objects.
In the Airlines class I have (which can’t be edited or changed, this was the header file given to me for the assignment):
//Airline.h
class Airline {
public:
Airline(); // default constructor
Airline(int capacity); // construct with capacity n
void cancel(int flightNum);
void add(Flight* flight);
Flight* find(int flightNum);
Flight* find(string dest);
int getSize();
private:
Flight **array; // dynamic array of pointers to flights
int capacity; // maximum number of flights
int size; // actual number of flights
void resize();
};
//Flight.h
class Flight {
public:
Flight();
// Default constructor
Flight(int fnum, string destination);
void reserveWindow();
void reserveAisle();
void reserveSeat(int row, char seat);
void setFlightNum(int fnum);
void setDestination(string dest);
int getFlightNum();
string getDest();
protected:
int flightNumber;
bool available[20][4]; //only four seat types per row; only 20 rows
string destination;
};
I’m trying to impliment one of the find methods in the class.
for that, I have:
Flight* Airline::find(int flightNum){
bool found = false;
for(int i = 0; i < size; i++){
if(array[i].getflightNum() == flightNum){
found = true;
return array[i];
}
}
if(!found)
return 0;
}
// Return pointer to flight with given number if present, otherwise
// return 0.
But it’s saying that I need a class type when trying to call the getFlightNum() method. I don’t really understand the error. Am I not calling the method correctly? What is the correct syntax?
Since you are dealing with pointers instead of actual objects, try this: