Thread: strange error

  1. #1
    Registered User
    Join Date
    Jan 2003

    strange error

    Im doing seperate compilation and recieiving this error:

    Undefined first referenced
    symbol in file
    Event::myFile /var/tmp/ccDP8O3f.o
    Simulation:laneList /var/tmp/ccEJRun1.o
    PlaneList::PlaneList(void) /var/tmp/cciNSKJz.o
    Simulation::takeoffQ /var/tmp/ccKmDc8W.o
    Simulation::landingQ /var/tmp/ccEJRun1.o
    Simulation::eventList /var/tmp/ccEJRun1.o
    ld: fatal: Symbol referencing errors. No output written to a.out
    collect2: ld returned 1 exit status

    now, all of them are static, although myFile is private.

    Here is the Event class, since it's the only one who actually has any myFile in it.

    NOTE: we have to use strsteam and not a newer version due to schools system it runs on.

    #ifndef EVENT_H
    #define EVENT_H
    #include "Object.h"
    #include "Plane.h"	//making an instance of plane
    #include "Simulation.h"
    #include "PlaneList.h"
    #include "Queue.h"
    #include "EventList.h"
    class Event : public Object
    		int time;
    		Plane* plane;
    		static ifstream myFile;
    		void setPlane(Plane* plane);
    		void setTime(int time);
    		void makeItHappen();
    		bool getNextArrival();
    		string toString();
    		int getTime();
    		Plane* getPlane();
    		static void open(string fileName);
    //here is the cpp file
    #include <iostream>
    #include <fstream>
    #include <strstream>
    #include "Event.h"
    #include "NiceOutput.h"
    #include "Arrival.h"
    #include "Depart.h"
    #include "Landing.h"
    #include "TakeOff.h"
    #include "Plane.h"	//making an instance of plane
    #include "Simulation.h"
    int Event::getTime()
    	return time;
    void Event::setTime(int time)
    	this->time = time;
    Plane* Event::getPlane()
    	return plane;
    void Event::setPlane(Plane* plane)
    	this->plane = plane;
    void Event::makeItHappen()
    	//jump forward in time to the indicated event, then
    	//manifest the changes made to that event.  We know what
    	//time it is, so we print out that part of the output message
    	//for the event first.
    	cout << "Time" << NiceOutput::rightAlign(time,4) << ": Plane " << NiceOutput::rightAlign(getPlane()->getFlightNum(),2);
    	//just call a method based on the event type
    	if (dynamic_cast<Arrival*>(this) !=NULL)
    		Arrival* arrive = (Arrival*)this;
    		cout<<" arrives";
    	else if (dynamic_cast<Landing*>(this) !=NULL)
    		Landing* land = (Landing*)this;
    		cout << " lands";
    	else if (dynamic_cast<Depart*>(this) !=NULL)
    		Depart* departure = (Depart*)this;
    		cout <<" departs";
    	else if (dynamic_cast<TakeOff*>(this) !=NULL)
    		TakeOff* takeOff = (TakeOff*)this;
    		cout << " takes off";
    		//always good to have a catch all taht will give
    		//you an informative message!
    		cout << "Invalid Event:";
    		cout << toString();
    		cout << "Halting Abnormally";
    bool Event::getNextArrival()
    	//returns true if we successfully read the next arrival
    	//from the file...
    	string fileLine; //line from input text file!
    	int groundTime; //min required ground time for upcoming plane
    	bool success=false; //did the read work?
    	//fileLine = ;
    	  //this either got a string or null if no data
    	if (!(Event::myFile.eof()))
    		//read some data
    		Event::myFile >> time >> groundTime;
    		  //waiting time is information about the flight itself,
    		  //we need to store it in the plane data structure inside
    		  //this event.
    		  success= true;
    		success = false; //no more arrivals...
    	return success;
    string Event::toString()
    	//give back the contents of the object in string form
    	ostrstream S;
    	S  <<" event for flight " << getPlane()->getFlightNum() << " at time " << time << ".";
    	string line = S.str();
    	return line;
    void Event::open(string fileName)
    no idea why myFile should be getting the undefined error, Ive looked over the code several times and Im probably just misreading it.
    Last edited by peking1983; 03-10-2003 at 10:03 PM.

  2. #2
    Registered User
    Join Date
    Jan 2003
    here is the mainLine
    #include "Event.h"
    #include "Simulation.h"
    #include "NiceOutput.h"
    #include "Queue.h"
    #include "EventList.h"
    #include "PlaneList.h"
    #include "Arrival.h"
    int main()
    	//a few variables necessary to read in the file
    	//name and set up the input file...
    	string fileName = ""; //name of the file to be used!
    //	ifstream myFile;
    	//prompt for the desired input file name
    	//bind the stream to system input, then read after prompting
    	//exit with error code if we fail to do this
    	cout << "Please enter input file name:";
    	cin >>  fileName;
    	// attempt to open the data file.  Exit with error code on fail.
    	//create the necessary data structures for the simulation
    	Simulation::eventList = new EventList();
    	Simulation::landingQ = new Queue();
    	Simulation::takeoffQ = new Queue();
    	Simulation::planeList = new PlaneList();
    	//prime the simulation by setting up the first arrival -
    	//processing each arrival will read in the next.
    	//first, make a new event...
    	Event* currentEvent = (Event*)(new Arrival());
    	//then attempt to get data for it...
    	if (currentEvent->getNextArrival())
    		//there's an arrival to be processed - enter it as an event
        	//run the simulation until there's nothing left in the
       		//event list - processing each arrival will cause the next future
        	//arrival to be inserted into the evne
    		cout << "Simulation begins...\n\n";
    		//keep going as long as the event list isn't empty.
    		while (!Simulation::eventList->isEmpty())
    			//just get the next event and process it...
    	 	//all events processed, just pring the final summary data.
    		cout << "/n...All events complete.  Final Summary:\n";
    		//NiceOutput contains all formatting routines.
    	}  //if
    	else    //we are done, there was nothing in the input file.
    		cout << "No arrivals in file = nothing to simulate!";
    	cout << "End of Processing";
    	return 1;
    } //main

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM