I seem to have a problem with my code, anytime I try to initialize the constructor PlaneList I recieve a not defined error. It shouldn't be because PlaneList.h is included. Assignment is due in hours and spent several just with this compile bug.
What I find weird is my EventList(which is similar toPlaneList, and extends OrderedList) works perfectly fine, with a call to the constructor almost identical.
Any foolish things I'm doing wrong?
Undefined first referenced
symbol in file
PlaneList::PlaneList(void) /var/tmp/ccjIE1oK.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
Code:
// CLASS: Simulation Header
//
// REMARKS: constrols all simulation related things - many static variables
//
// INPUT: none
//
// OUTPUT: none
//
//-----------------------------------------
#ifndef SIMULATION_H
#define SIMULATION_H
class Queue;
class EventList;
class PlaneList;
using namespace std;
class Simulation
{
private:
//variables describing current status of the simulation
//these are altered by events (planes arriving and
//leaving), including flags for runway status
static int planesOnGround;
static bool isLandRunwayFree;
static bool isTakeoffRunwayFree;
public:
//queues for landing and departing flights!
static Queue* landingQ;
static Queue* takeoffQ;
//also need a list of planes and a list of events
static EventList* eventList;
static PlaneList* planeList;
//parameters for the simulation, things we might want
//to change in future runs
//you should always think ahead and try to parameterize
//things!
static const int MAX_PLANES=4; //max # planes on ground @ once
static const int LANDING_DELAY=5; //time delay for landing op
static const int TAKEOFF_DELAY=5; //time delay for takeoff op
//methods to alter the state of the simulation
//planesUp: increase the number of planes indicated
//as being on the ground.
static void planesUp();
//planesDown: decrease the number of planes indicated
//as being on the ground.
static void planesDown();
//return the number of planes currently on the ground
static int getPlaneCount();
//access methods for runway flags: two for retrieving
//their values, and methods that allow us to set and clear
//each of these flags.
static bool landRunwayFree();
static bool takeoffRunwayFree();
static void setLandRunwayOccupied();
static void setLandRunwayFree();
static void setTakeoffRunwayOccupied();
static void setTakeoffRunwayFree();
};
#endif
//---------------------------------------------------------------
// CLASS: Simulation
//
// REMARKS: methods and initializer for static values
//
// INPUT: none
//
// OUTPUT: none
//
//-----------------------------------------
#include<iostream>
#include "Simulation.h"
#include "PlaneList.h"
#include "Queue.h"
#include "EventList.h"
int Simulation::planesOnGround = 0;
bool Simulation::isLandRunwayFree = true;
bool Simulation::isTakeoffRunwayFree = true;
PlaneList* Simulation::planeList = new PlaneList();
EventList* Simulation::eventList = new EventList();
Queue* Simulation::landingQ = new Queue();
Queue* Simulation::takeoffQ = new Queue();
//planesUp: increase the number of planes indicated
//as being on the ground.
void Simulation::planesUp()
{
Simulation::planesOnGround++;
}
//planesDown: decrease the number of planes indicated
//as being on the ground.
void Simulation::planesDown()
{
Simulation::planesOnGround--;
}
//return the number of planes currently on the ground
int Simulation::getPlaneCount()
{
return Simulation::planesOnGround;
}
//access methods for runway flags: two for retrieving
//their values, and methods that allow us to set and clear
//each of these flags.
bool Simulation::landRunwayFree()
{
return isLandRunwayFree;
}
bool Simulation::takeoffRunwayFree()
{
return isTakeoffRunwayFree;
}
void Simulation::setLandRunwayOccupied()
{
isLandRunwayFree = false;
}
void Simulation::setLandRunwayFree()
{
isLandRunwayFree = true;
}
void Simulation::setTakeoffRunwayOccupied()
{
isTakeoffRunwayFree = false;
}
void Simulation::setTakeoffRunwayFree()
{
isTakeoffRunwayFree = true;
}
//---------------------------------------------------------------
// CLASS: PlaneList header
//
// REMARKS: list of planes
//
// INPUT: none
//
// OUTPUT: none
//
//-----------------------------------------
#ifndef PLANELIST_H
#define PLANELIST_H
#include "OrderedList.h"
class Object;
using namespace std;
class PlaneList : public OrderedList
{
private:
public:
PlaneList()
{
setFirst(NULL); //empty list to start!
};
bool smaller(Object* listItem, Object* newData);
};
#endif
// CLASS: PlaneList
//
// REMARKS: abstract smaller method PlaneList must use
//
// INPUT: objects smaller is comparing
//
// OUTPUT: none
//
//-----------------------------------------
#include <iostream>
#include "PlaneList.h"
#include "Plane.h"
#include "Simulation.h"
bool smaller(Object* listItem, Object* newData)
{
//is the listItem smaller than the new data?
//the abstract list these are from is a list of Objects, so
//we need to cast them back to Planes.
bool result;
//plane 1 is smaller than plane 2 if it has a lower flight number
if ( ((Plane*) listItem)->getFlightNum() < ((Plane*) newData)->getFlightNum() )
result=true;
else
result= false;
return result;
}