Compile Error that i dont understand

This is a discussion on Compile Error that i dont understand within the C++ Programming forums, part of the General Programming Boards category; Any ideas what this compile error is? Code: In file included from Application.cpp:5: Airport.h:12: syntax error before `*' token Application.cpp:8: ...

  1. #1
    Matt Conway bobthebullet990's Avatar
    Join Date
    Nov 2005
    Location
    Cambridge
    Posts
    121

    Compile Error that i dont understand

    Any ideas what this compile error is?

    Code:
    In file included from Application.cpp:5:
    Airport.h:12: syntax error before `*' token
    Application.cpp:8: semicolon missing after declaration of `Application'
    Application.cpp:8: parse error before `using'
    Application.cpp:8: `string' specified as declarator-id
    Application.cpp:8: two or more data types in declaration of `string'
    Application.cpp:8: `int std::string' redeclared as different kind of symbol
    /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/../../../include/g++-v3/bits/stringfwd.h:63: previous
       declaration of `typedef struct std::basic_string<char, 
       std::char_traits<char>, std::allocator<char> > std::string'
    Application.cpp: In function `int main()':
    Application.cpp:41: no match for `std::istream& << int&' operator
    Application.cpp:64:2: warning: no newline at end of file
    Flight.cpp:20: parse error before `public'
    Flight.cpp:11: warning: all member functions in class `Flight::Flight' are 
       private
    Flight.cpp:82: parse error at end of input
    OK, my files....

    Airport.h
    Code:
    // Airport.h
    
    #include <string>
    
    using std::string;
    
    class Airport {  
    
     private:
      // Class Variables
      static const int MAXFLIGHTS = 100;
      Flight * flights[MAXFLIGHTS]; 
      string airportName;
      string airportID;
      int numFlights;
      
     public:
      
      // Class Methods
      int addFlight(string, string, string, string, string);
      string getFlightDetails(string);
      string getAirportID();
      string getAirportName();
      
      // Constructor for airport
      Airport(string, string);
      
    }; // class Airport
    Airport.cpp
    Code:
    // Airport.cpp
    
    #include <iostream>
    #include <string>
    #include "Flight.h"
    #include "Airport.h"
    
    using std::string;
    using std::cout;
    using std::cin;
    using std::getline;
    using std::endl;
    
    Airport :: Airport(string inID, string inName) {
      
      airportID = inID;      // set airport id
      airportName = inName;  // set airport name
      numFlights = 0;        // Number of flight objects in array
    
      // Initialise the array of flight objects
      for (int i = 0; i < MAXFLIGHTS; i++) {
        flights[i] = 0;
      }
      
    } // Airport
    
    // Function to add a flight to the aiport.
    int Airport :: addFlight(string inFlightID, 
                             string inOrigin, 
                             string inDestination, 
                             string inDeparture, 
                             string inArrival) {
      // Check there is enough free space in the array to add new flight.  
      if (numFlights < MAXFLIGHTS) {
        // add the flight object to the array of flights.
        flights[numFlights] = new Flight(inFlightID, 
                                         airportID, 
                                         inDestination, 
                                         inDeparture,
                                         inArrival);
        numFlights++; // increment flight counter.
        return 0;     // flight added, return no error.
      }
      else {
        return -1;    // no space to add flight. return error.
      }
    
    } // addFlight
    
    // Function to get the aiport id 
    string Airport :: getAirportID() {
      return airportID;
    }
    
    string Airport :: getAirportName() {
      return airportName;
    }
    
    // Function to return a formatted string containing flight details
    string Airport :: getFlightDetails(string inFlight) {
      
      string retval; // string to store formatted return value
      
      for (int i = 0; i < MAXFLIGHTS; i++) {
        // Is the object blank?
        if (flights[i] == 0) {
          break; // Flight not found
        }
        // Is the current flight the one being searched for?
        else if (flights[i]->getFlightID() == inFlight) {
          retval =  flights[i]->getFlightID() + '\n' 
                  + flights[i]->getFlightOrigin() + '\n' 
                  + flights[i]->getFlightDestination() + '\n' 
                  + flights[i]->getFlightDeparture() + '\n' 
                  + flights[i]->getFlightArrival() + '\n';
          // found the flight, so return the formatted string.
          return retval;
        }
      } 
      
      // ERROR! If reach here, no such flight was found. return error msg
      return "ERROR! No such flight exists!\n";
    }
    Flight.h
    Code:
    // Flight.h
    
    #include <string>
    
    using std::string;
    
    class Flight {
      
    private:
      // Class Variables
      string id;
      string origin;
      string destination;
      string departure;
      string arrival;
    
    public:
      // Class Methods
      string getFlightID();
      string getFlightOrigin();
      string getFlightDestination();
      string getFlightDeparture();
      string getFlightArrival();
      void setDeparture(string);
      void setArrival(string);
      
      // Constructor Prototype
      Flight(string, string, string, string, string); 
    };
    Flight.cpp
    Code:
    // Flight.cpp
    
    #include <string>
    
    using std::string;
    
    class Flight {
    
    private: 
    
    class Flight {
      private:
      // Class Variables
      string id;
      string origin;
      string destination;
      string departure;
      string arrival
    
    public:
      // Class Methods
      string getFlightID();
      string getFlightOrigin();
      string getFlightDestination();
      string getFlightDeparture();
      string getFlightArrival();
      void setFlightDeparture(string);
      void setFlightArrival(string);
    
      // Constructor Prototype
      Flight(string, string, string, string, string); 
    
    }; // class Flight
    
    Flight :: Flight(string inID, string inOrigin, string inDestination, string inDe
    parture, string inArrival){
    
      id = inID;
      origin = inOrigin;
      destination = inDestination;
      departure = inDeparture;
      arrival = inArrival;
    
    } // Flight constructor
    
    // function to get the flight id number
    string Flight :: getFlightID() {
      return id;
    }
    
    // function to get the flight origin
    string Flight :: getFlightOrigin() {
      return origin;
    }
    
    // function to get the flight destination
    string Flight :: getFlightDestination() {
      return destination;
    }
    
    // function to get the flight departure time
    string Flight :: getFlightDeparture() {
      return departure;
    }
    
    // Function to get the flight arrival time
    string Flight :: getFlightArrival() {
      return arrival;
    }
    
    // Function to set the flight depature time - maybe delay
    void setFlightDeparture(string inData) {
      depature = inData;
    }
    
    // Function to set the flight arrival time - maybe delay
    void setFlightArrival(string inData) {
      arrival = inData;
    }
    Application.h
    Code:
    class Application {
     private:
      static const int MAXAIRPORTS = 100;
      Airport * airports[MAXAIRPORTS];
      int numAirports;
      
     public:
      
       // Class methods
       void addAirport();
       void selectAirport();
       
       // constructor for application
       Application();
       
    } // class Application
    Application.cpp
    Code:
    // Application.cpp
    
    #include <iostream>
    #include <string>
    #include "Airport.h"
    #include "Application.h"
    
    using std::string;
    using std::cout;
    using std::cin;
    using std::getline;
    using std::endl;
    
    Application :: Application() {
    } // Constructor
    
    // Function to add an airport object to the application
    void Application :: addAirport() {
      cout << "add airport" << endl;
    }
    
    // Function to select an existing airport in the application
    void Application :: selectAirport() {
      cout << "select airport" << endl;
    }
    
    int main() {
      
      int input;
      bool active = true, isError = true; 
      Application myApplication; // create a user Application class
      
      while (active) { // loop whilst user does not want to quit
        
        while (isError) { // Loop whilst an invalid choice
          
          cout << " - AIRPORT SYSTEM - " << endl;
          cout << " 1. Add Airport" << endl;
          cout << " 2. Select Airport" << endl;
          cout << " 3. Quit Application" << endl;
          cin << input;
        
          switch(input) {
          case 1: // Add airport
            myApplication.addAirport();
            isError = false;
            break;
          case 2: // Select airport
            myApplication.selectAirport();
            isError = false;
            break;
          case 3: // quit
            isError = false;
            break;
          default: 
            cout << "ERROR! Invalid Input! Try Again!" << endl;
          } // switch
          
        } // while(isError)
      
      } // while(active)
      
      return 0; // finished program
    }

    Well... The deadline for this coursework has passed, I have handed in the above, looks like a resit for me! ...not bothered cause spend all my time doing the device driver coursework for a ported linux installation and it was pretty sweet! ...Well; any help much appriciated cause i don't have a clue what im doin ni C++ and it will help for my resit coursework in July! Cheers!

  2. #2
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    You're missing a semicolon after application class declaration.

    It's hard to tell where the errors lie because no line numbers or section where the errors occur.
    Last edited by indigo0086; 05-05-2006 at 06:43 AM.

  3. #3
    Matt Conway bobthebullet990's Avatar
    Join Date
    Nov 2005
    Location
    Cambridge
    Posts
    121
    OK!!! ...Managed to get rid of most errors! ...but there are still these..... and they change depending on which files i compile first! what the hell is going on! I HATE C++; so many files to think about so many variables to consider! its rubbish, bring back the C!

    Code:
    mconway@milly [110] g++ Application.cpp Airport.cpp Flight.cpp
    In file included from Airport.h:5,
                     from Application.h:5,
                     from Application.cpp:6:
    Flight.h:7: redefinition of `class Flight'
    Flight.h:7: previous definition of `class Flight'
    In file included from Application.h:5,
                     from Application.cpp:6:
    Airport.h:9: redefinition of `class Airport'
    Airport.h:9: previous definition of `class Airport'
    mconway@milly [111] g++ Flight.cpp Airport.cpp Application.cpp
    In file included from Airport.h:5,
                     from Application.h:5,
                     from Application.cpp:6:
    Flight.h:7: redefinition of `class Flight'
    Flight.h:7: previous definition of `class Flight'
    In file included from Application.h:5,
                     from Application.cpp:6:
    Airport.h:9: redefinition of `class Airport'
    Airport.h:9: previous definition of `class Airport'

  4. #4
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Code:
    #include <string>
    
    using std::string;
    
    class Flight {
    
    private: 
    
    class Flight {
      private:
    ...
    the word flight shows up twice, which looks like two defenitions

    seems you did the same with airport. Try clicking on the errors so it takes you to them and look around

  5. #5
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    In addition what indigo0086 said. You declare the classes Flight and Airport in the header and in the implementation ( .cpp ) file, so remove the declarations from the .cpp-files.
    Kurt

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    You need header include guards in your header files. You also need to forward declare the Flight class in Airport.h.

    BTW, I'd recommend a vector of Flight* instead of guessing a good value for MAXFLIGHTS. With a vector, there is no max, you can keep pushing back new flights.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Example from book, don't understand.
    By RealityFusion in forum C++ Programming
    Replies: 1
    Last Post: 09-30-2005, 03:47 PM
  2. open scene graph compile issues
    By ichijoji in forum Game Programming
    Replies: 1
    Last Post: 08-04-2005, 12:31 PM
  3. header file compile error
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 02-23-2002, 05:28 AM
  4. Replies: 4
    Last Post: 11-14-2001, 09:28 AM
  5. how do i compile a program that deals w/classes?
    By Shy_girl_311 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2001, 01:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21