C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-05-2006, 06:34 AM   #1
Junglist
 
bobthebullet990's Avatar
 
Join Date: Nov 2005
Location: Bristol
Posts: 118
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!
bobthebullet990 is offline   Reply With Quote
Old 05-05-2006, 06:38 AM   #2
Ethernal Noob
 
Join Date: Nov 2001
Posts: 1,888
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.
indigo0086 is offline   Reply With Quote
Old 05-05-2006, 06:51 AM   #3
Junglist
 
bobthebullet990's Avatar
 
Join Date: Nov 2005
Location: Bristol
Posts: 118
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'
bobthebullet990 is offline   Reply With Quote
Old 05-05-2006, 07:14 AM   #4
Ethernal Noob
 
Join Date: Nov 2001
Posts: 1,888
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
indigo0086 is offline   Reply With Quote
Old 05-05-2006, 09:14 AM   #5
ZuK
Registered User
 
Join Date: Aug 2005
Posts: 1,303
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
ZuK is offline   Reply With Quote
Old 05-05-2006, 09:19 AM   #6
Registered User
 
Join Date: Jan 2005
Posts: 7,137
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.
Daved is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Example from book, don't understand. RealityFusion C++ Programming 1 09-30-2005 03:47 PM
open scene graph compile issues ichijoji Game Programming 1 08-04-2005 12:31 PM
header file compile error Unregistered C Programming 5 02-23-2002 06:28 AM
gcc compile on cmd line, then run, get: bash: hello: command not found cjtotheg Linux Programming 4 11-14-2001 10:28 AM
how do i compile a program that deals w/classes? Shy_girl_311 C++ Programming 5 11-11-2001 02:32 AM


All times are GMT -6. The time now is 06:20 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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