I have two classes that need to know about each other. But whenever I #include "Theother.h", I get no-type errors.
Code:
/*
* PCB.h
* 3146Assignment4
*
* Created by Sterling McLeod on 10/6/10.
* Copyright 2010 University of North Carolina at Charlotte. All rights reserved.
*
*/
#ifndef PCB_H
#define PCB_H
#define HOLD 0
#define READY 1
#define WAITING 2
#define RUNNING 3
#define FINISHED 4
#include "Job.h"
class PCB {
public:
PCB(Job&);
~PCB();
int& getRegisterCounter();
void setRegisterCounter(int c);
int& getProcessStatus();
void setProcessStatus(int p);
std::string getJobID();
void setJob(Job&);
Job& getJob();
private:
int registerCounter;
int processStatus;
std::string jobID;
Job* job;
};
#endif
Code:
/*
* PCB.cpp
* 3146Assignment4
*
* Created by Sterling McLeod on 10/6/10.
* Copyright 2010 University of North Carolina at Charlotte. All rights reserved.
*
*/
#include "PCB.h"
PCB::PCB(Job& j) : job(&j) {
jobID = j.getDescription();
registerCounter = 0;
processStatus = HOLD;
}
PCB::~PCB() {}
int& PCB::getRegisterCounter() {return registerCounter;}
void PCB::setRegisterCounter(int c) {registerCounter = c;}
int& PCB::getProcessStatus() {return processStatus;}
void PCB::setProcessStatus(int p) {processStatus = p;}
std::string PCB::getJobID() {return jobID;}
void PCB::setJob(Job& j) {job = &j;}
Job& PCB::getJob() {return *job;}
Code:
/*
* Job.h
* 3146Assignment4
*
* Created by Sterling McLeod on 10/6/10.
* Copyright 2010 University of North Carolina at Charlotte. All rights reserved.
*
*/
#ifndef JOB_H
#define JOB_H
#include <string>
#include "PCB.h"
class Job {
public:
Job(int cycle, std::string descrip);
~Job();
void setCPUCycle(int x);
int& getCPUCycle();
PCB& getPCB();
void setPCB(PCB&);
void makePCB();
int& getWaitingTime();
void setWaitingTime(int t);
int& getTurnaroundTime();
void setTurnaroundTime(int t);
std::string getDescription();
private:
int waitingTime;
int turnaroundTime;
int cpuCycle;
std::string description;
PCB* pcb;
};
#endif
Code:
/*
* Job.cpp
* 3146Assignment4
*
* Created by Sterling McLeod on 10/6/10.
* Copyright 2010 University of North Carolina at Charlotte. All rights reserved.
*
*/
#include "Job.h"
Job::Job(int cycle, std::string descrip) :
cpuCycle(cycle), description(descrip) {}
Job::~Job() {}
void Job::setCPUCycle(int x) {cpuCycle = x;}
int& Job::getCPUCycle() {return cpuCycle;}
PCB& Job::getPCB() {return pcb;}
void Job::setPCB(PCB& p) {pcb = p;}
void Job::makePCB() {
PCB* apcb = new PCB(this);
this->setPCB(apcb);
}
int& Job::getWaitingTime() {return waitingTime;}
void Job::setWaitingTime(int t) {waitingTime = t;}
int& Job::getTurnaroundTime() {return turnaroundTime;}
void Job::setTurnaroundTime(int t) {turnaroundTime = t;}
std::string Job::getDescription() {return description;}
I tried using forward declarations, but it still gave me the same problems. Can anyone tell me a way to fix this? Any help is appreciated, thanks.