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.
Code:
#ifndef EVENT_H
#define EVENT_H
#include<string>
#include<fstream>
#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
{
private:
int time;
Plane* plane;
static ifstream myFile;
protected:
void setPlane(Plane* plane);
void setTime(int time);
public:
void makeItHappen();
bool getNextArrival();
string toString();
int getTime();
Plane* getPlane();
static void open(string fileName);
};
#endif
//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";
arrive->processArrival();
}
else if (dynamic_cast<Landing*>(this) !=NULL)
{
Landing* land = (Landing*)this;
cout << " lands";
land->processLanding();
}
else if (dynamic_cast<Depart*>(this) !=NULL)
{
Depart* departure = (Depart*)this;
cout <<" departs";
departure->processDeparture();
}
else if (dynamic_cast<TakeOff*>(this) !=NULL)
{
TakeOff* takeOff = (TakeOff*)this;
cout << " takes off";
takeOff->processTakeoff();
}
else
{
//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.
getPlane()->setGroundTime(groundTime);
success= true;
}
else
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 << ".";
S.put(0);
string line = S.str();
return line;
}
void Event::open(string fileName)
{
myFile.open(fileName.c_str());
}
no idea why myFile should be getting the undefined error, Ive looked over the code several times and Im probably just misreading it.