I am trying to do a priority queue with a custom type, but I keep getting this error
des.cpp:77: error: expected init-declarator before "eventQ"
des.cpp:77: error: expected `;' before "eventQ"
This happens in the following code
Program: This is a discrete event simulator designed to aid in the analysis
* of particular scheduling algorithms for comparison of efficiency
*/
//the following macro generates a random number between A and B
#define RAND_RANGE(A,B) ( (A) + ((B)-(A))*(double)rand( ) / RAND_MAX )
#include <time.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/times.h>
#include <sys/stat.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/socket.h>
#include <signal.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <vector>
#include <queue>
using namespace std;
enum evTyp { PARVL = 0, CPUEND = 1, IOEND = 2};
/*
The strtTime is a random number generated by the RAND_RANGE for range 0-300
The endTime is a random number generated by RAND_RANGE( for range 1-60
When the CPUtime + IOtime become >= to the endTime, then after the next CPU burst event
is logged, the process is ended
The CPUtime effectively stores the time of a CPU burst determined by randCPU_Burst function
The IOtime effectively stores the IO time that the process waited in the IOqueue
IOqStrt is used for time it gets into the IO queue
*/
struct Evnt
{
int pid;
evTyp type;
double strtTime;
double endTime;
double evTime;
double CPUtime;
double IOtime;
double IOqStrt;
};
Evnt operator<(const Evnt& x, const Evnt& y)
{
if(x.evTime < y.evTime)
{
return x;
}
return y;
}
template <
class Type,
class Container=vector<Type>,
class Compare=less<typename Container::value_type>
>
class priority_queue
priority_queue<Evnt, vector<Evnt>,less<vector<Evnt>::value_type> > eventQ;
that last line of the code is line 77 where the error is occurring. I have no idea what I'm doing wrong. I thought maybe I was using a predefined name type when I had it called Event, but changing it to Evnt still didn't fix the trouble. I just dunno what is wrong with it, and this error explanation doesn't make sense to me.