Hi guys,
I'm writing a class that has as pair of static int members...pretty easy, I know, but it's not working. The linker tells me I have unresolved external symbols associated with my static members. Any ideas?
Also, does anyone know of some good online documentation on Hash Tables? SGIs info is pretty cryptic sometimes.
Thanks!
Code:
job.h
#ifndef JOB_H
#define JOB_H
#include<iostream>
#include<vector>
using namespace std;
class Job
{
private:
static int machPerJob, numOfMach;
int startTime, endTime;
vector<char> machines;
char schedule;
public:
Job();
Job(int, int, vector<char>);
static void setMachPerJob(int);
static int getMachPerJob();
static void setNumOfMach(int);
void setSchedule(char sched);
friend ostream& operator<<(ostream& os, const Job& job);
friend istream& operator>>(istream& is, Job& job);
};
#endif
job.cpp
#include<vector>
#include"job.h"
using namespace std;
Job::Job()
{
startTime = endTime = -1;
schedule = '-';
}
Job::Job(int start, int end, vector<char> mach)
{
startTime = start;
endTime = end;
machines = mach;
schedule = '-';
}
void Job::setMachPerJob(int mpj)
{
machPerJob = mpj;
}
int Job::getMachPerJob()
{
return machPerJob;
}
void Job::setNumOfMach(int nom)
{
numOfMach = nom;
}
void Job::setSchedule(char sched)
{
schedule = sched;
}
ostream& operator << (ostream& os, const Job& job)
{
os << job.startTime << " " << job.endTime << " " << job.schedule;
return os;
}
istream& operator >> (istream& is, Job& job)
{
int start, end;
char tempMach;
is >> start >> end;
job.startTime = start;
job.endTime = end;
for (int i = 0; i < Job::getMachPerJob(); i++)
{
is >> tempMach;
job.machines.push_back(tempMach);
}
return is;
}
main.cpp
#include<iostream>
#include<fstream>
#include<vector>
//#include<unistd.h>
#include"job.h"
//void parseCommandLine(int, char**, char*&, char*&, char*&, bool&)
int main(int argc, char** argv)
{
char *algor = "Recursive", *cacheFile = "testcase1.txt", *schedFile = "schedule.txt";
bool helpFlag = false;
int tempMachPerJob, tempNumOfMach, i;
Job tempJob;
vector<Job> jobs;
//parseCommandLine(argc, argv, algor, cacheFile, schedFile, helpFlag);
ifstream inFile(cacheFile);
if (inFile.fail())
{
cout << "Error opening input file!" << endl;
exit(1);
}
inFile >> tempMachPerJob >> tempNumOfMach;
Job::setMachPerJob(tempMachPerJob);
Job::setNumOfMach(tempNumOfMach);
inFile >> tempJob;
while (inFile)
{
jobs.push_back(tempJob);
inFile >> tempJob;
}
for(i = 0; i < jobs.size(); i++)
cout << jobs[i] << endl;
return 0;
}
/*void parseCommandLine(int argc, char** argv, char*& algor, char*& cacheFile,
char*& schedFile, bool& helpFlag)
{
int c;
while ((c = getopt(argc, argv, "a::i::o::h")) != -1)
{
switch (c) // Switch on flags, etc
{
case 'a':
algor = optarg;
break;
case 'i':
cacheFile = optarg;
break;
case 'o':
shcedFile = optarg;
break;
case 'h':
helpFlag = true;
break;
case '?':
cerr << "Argument Error!" << endl;
exit(1);
default:
break;
} // Switch on getopt return value
}
return;
}*/