Sorry but this is really confusing me and I know the answer is staring at me in the face and I can't figure it out. Could someone take a look? Its for a Airline Reservation System school project.
This function takes in the Flight Number, capacity, the count of the number of flights, and the vector containing all of the flights as arguments. It will check to make sure the flight does not exist, if it exists an error message will be displayed, if not the flight will be created. The count for the number of flights will also be incremented.
void newFlight( string f, string s, int* n, vector<Flight> *v)
{
Flight temp;
//Check to see if flight number exists
bool alreadyExist = false;
for (int i=0; i < v->size(); i++)
{
if (f.compare((v[i].getNumber()) == 0))
alreadyExist = true;
}
//If it doesn't exist, create it
if (!alreadyExist)
{
v->push_back (temp); //Add the new Flight object to the
//vector of flights
*n++; //Increase count
}
else
{
cout << "A flight numbered " << f << " already exists";
cout << ". Flight not created.\n";
}
};
My problem is that when I try to compare the flight number the flights already in the vector with the one I am trying to add. On line 7 I keep getting this message:
error:
‘class std::vector<Flight, std::allocator<Flight> >’
has no member named ‘getNumber’
The vector in question is a vector with the Flight class which has a member named getNumber(). Im passing the vector to the function by reference. So v is a pointer, but I thought the [] would take care of that. Ive also tried using the -> operator instead of the dot operator but it doesn't help. Im at a loss, any help would be appreciated. Im relatively rusty, the summer just finished :D Also I hope this is formatted correctly.