Confusing object issue....

I'm trying to set up this project but I'm getting caught on strange errors.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<iostream>
#include<fstream>
#include<string>
#include<cstdlib>
#include<sstream>
#include"flights.h"
#include"reservations.h"

using namespace std;

void GetFile(string, ifstream&);
bool GetCommand(Flights& , Reservations&);
void AddReservation(string, Flights&, Reservations&);
void DeleteReservation(string, Flights&, Reservations&);

int main(int argc, char *argv[])
{
        bool quit = false;
        string filename;
        if(argc < 2)
        {
                cout << "Require filename for flight information. Aborting." <<$
                return(EXIT_FAILURE);
        }
        else
                filename = argv[1];
        ifstream inFile;
        GetFile(filename, inFile);
        if(!inFile)
        {
                cout << "Failed to open data file. Aborting." << endl;
                return(EXIT_FAILURE);
        }
        Flights flights(inFile);
        Reservations reservations();
        while(!quit)    
        quit = GetCommand(flights, reservations);
        inFile.clear();
        inFile.close();
        return(0);

}


For some reason, when I go to compile in G++, I get the following error(s).

proj1.cpp: In function âint main(int, char**)â:
proj1.cpp:34: error: conflicting declaration âFlights inFileâ
proj1.cpp:27: error: âinFileâ has a previous declaration as âstd::ifstream inFileâ
proj1.cpp:37: error: expected primary-expression before â,â token
proj1.cpp:37: error: expected primary-expression before â)â token


Also, later on, I have a problem here as well.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
bool GetCommand(Flights& flights, Reservations& reservations)
{
        bool quit = false;
        string input;
        string command;
        string entrydata;
        cout << "Reservations>>";
        getline(cin, input);
        istringstream iss(input);
        iss >> command;
        getline(iss, entrydata);
        cout << entrydata;
        if(command == "new")
                flights.NewFlight(entrydata);
        else if(command == "quit")
                quit = true;
        else if(command == "add")
                AddReservation(entrydata, flights, reservations);
        else if(command == "delete")
                DeleteReservation(entrydata, flights, reservations);
        else if(command == "is")
                reservations.CheckReservation(entrydata);
        else if(command == "lookup")
                reservations.FindReservations(entrydata);
        else if(command == "display")
                reservations.FlightRoster(entrydata);
        else           
                cout << "Command not recognized" << endl;

        return(quit);
}


and get these errors
proj1.cpp: In function âbool GetCommand(Flights&, Reservations&)â:
proj1.cpp:57: error: expected primary-expression before â.â token
proj1.cpp:61: error: expected primary-expression before â,â token
proj1.cpp:61: error: expected primary-expression before â)â token
proj1.cpp:63: error: expected primary-expression before â,â token
proj1.cpp:63: error: expected primary-expression before â)â token
proj1.cpp:65: error: expected primary-expression before â.â token
proj1.cpp:67: error: expected primary-expression before â.â token
proj1.cpp:69: error: expected primary-expression before â.â token


Anyone got any ideas on how to fix this?
Looks like you have some weird problem with your Flights class.

Can you post flights.h?
#ifndef flights
#define flights

#include<iostream>
#include<string>
#include<vector>

using namespace std;

struct flightinfo
{
string number;
int seats;
};

class Flights {

public:
Flights(ifstream& f);
void NewFlight(string n, int s);
bool checkFlight(const string& m) const;
bool checkAvailable(const string& o) const;
void addPassenger(const string& p);
void removePassenger(const string& q);

private:
vector<flightinfo> info;
void ReadFile(ifstream& f);
void addtoRecord(string, int);

};

#endif
Nevermind, I somehow fixed it. Thanks anyways. ^^
Topic archived. No new replies allowed.