In my constructor in the preqrec.h header for a process request record object, it accepts two variables, its name and priority. However, I want to create a mini priority queue (a predefined STL) with a comparison statement in the declaration of the queue to make use of my boolean operator< specified in my header file.
I can't find in my book how exactly to compare one variable in a custom object, namely the priority value.
Here's my code
CODE
//preqrec.h
#ifndef PROCESS_REQUEST_RECORD_CLASS
#define PROCESS_REQUEST_RECORD_CLASS
#include <String>
#include <iostream>
using namespace std;
class procReqRec
{
public:
procReqRec();
//default constructor
procReqRec(const string& nm, int p);
//constructor
int getPriority();
string getName();
//access functions
void setPriority(int p);
void setName(const string& nm);
//update functions
friend bool operator< (const procReqRec& left, const procReqRec& right);
//for maintenence of a minimum priority queue
friend ostream& operator<< (ostream& ostr, const procReqRec& obj);
//output a process request record in the format
//name: priority
private:
string name; //process name
int priority; //process priority
};
procReqRec::procReqRec()
{
}
procReqRec::procReqRec(const string& nm, int p)
{
name = nm;
priority = p;
}
int procReqRec::getPriority()
{
return priority;
}
string procReqRec::getName()
{
return name;
}
void procReqRec::setPriority(int p)
{
priority = p;
}
void procReqRec::setName(const string& nm)
{
name = nm;
}
bool operator< (const procReqRec& left, const procReqRec& right)
{
return left.priority < right.priority;
}
ostream& operator<< (ostream& ostr, const procReqRec& obj)
{
return ostr << "Name: "<< obj.name << " Priority: " << obj.priority;
}
#endif
CODE
//program
#include <String>
#include <iostream>
#include <d_random.h>
#include <d_pqueue.h>
#include <preqrec.h>
using namespace std;
int main()
{
miniPQ<procReqRec, less<??> > mpq; //<--This is where I am having issues.
randomNumber rand;
mpq.push( procReqRec("Process A", rand.random(40)) );
mpq.push( procReqRec("Process B", rand.random(40)) );
mpq.push( procReqRec("Process C", rand.random(40)) );
mpq.push( procReqRec("Process D", rand.random(40)) );
mpq.push( procReqRec("Process E", rand.random(40)) );
mpq.push( procReqRec("Process F", rand.random(40)) );
mpq.push( procReqRec("Process G", rand.random(40)) );
mpq.push( procReqRec("Process H", rand.random(40)) );
mpq.push( procReqRec("Process I", rand.random(40)) );
mpq.push( procReqRec("Process J", rand.random(40)) );
while(!mpq.empty())
{
cout<<mpq.top()<< " ";
mpq.pop();
}
cout<<endl;
system("pause");
return EXIT_SUCCESS;
}