Hey guys. I'm having problems accessing thing in a class that I made. Code as follows.
Code:
//This class is going to hold all the info that I need to emulate the scheduler.
//More than likely, this will have a vector for itself.
class process
{
public:
process(); // Default constructor.
~process(); // Default destructor.
int getPriority(); // Returns the priority of the process
int getArr_Time(); // Returns the arrival time of the process
char getRTP(); // Returns either r or n for the value.
int getCPU_Burst(int burst_loc); // Returns the burst time at CPU_Burst[burst_loc]
int getIO_Burst (int burst_loc); // Returns the bust time at IO_Burst[burst_loc]
//Mutators
void setPriority(int pri); // change value of priority
void setArr_Time(int arr); // change value of arrival time
void setRTP(char rtp); // change value of RTP via rtp. make distinction
void setCPU_Burst(int loc, int val); //change the value of CPU_Burst[loc] to val.
void setIO_Burst(int loc, int val); //change the value of IO_Burst[loc] to val.
//variables for class so I dont' stupidly play with them.
private:
int priority; //the priority it has in the scheduler
int arr_time; //when it arrived
char RTP; //check for real time process status.
vector<int> CPU_Burst; //CPU burst. REason for vector is because we
// don't know if there will be seperate bursts for
// CPU work
vector<int> IO_Burst; //Time for IO bursts. Similar reasons for using
// a vector.
};
// END OF CLASS OUTLINE
// CLASS FUNCTION DEFINTIONS //
// Default Constructor. Only using default to simplify things.
// All set to incorrect values as this will ensure that I will have to change
// them to make them work right
process::process()
{
priority = -1;
arr_time = -1;
RTP = 'a';
CPU_Burst[0] = -1;
IO_Burst[0] = -1;
}
// This simply returns the priority.
int process::getPriority()
{
return priority;
}
// returns Arrival time of process
int process::getArr_Time()
{
return arr_time;
}
//returns the character representing weither or not it's a real time process
char process::getRTP()
{
return RTP;
}
//returns the value of CPU_Burst[burst_loc]
int process::getCPU_Burst(int burst_loc)
{
return CPU_Burst[burst_loc];
}
//returns the value of IO_Burst[burst_loc]
int process::getIO_Burst(int burst_loc)
{
return IO_Burst[burst_loc];
}
//Changes the priority of the process
void process::setPriority(int pri)
{
priority = pri;
}
//Changes Arrival time
void process::setArr_Time(int arr)
{
arr_time = arr;
}
//Changes the RTP status
void process::setRTP(char rtp)
{
RTP = rtp;
}
//changes cpu burst time at loc to val
void process::setCPU_Burst(int loc, int val)
{
//PROBLEM IS HERE:
CPU_Burst[loc] = val;
}
// changes io burst time at loc to val
void process::setIO_Burst(int loc, int val)
{
//PROBLEM IS ALSO PROBABLY HERE
IO_Burst[loc] = val;
}
process::~process()
{//Destructor. add stuff later maybe
}
// END FUNCTION DEFINITONS//
// END PROGRAM
//CLASS CODE HERE!
The code I've got compiles fine. And it runs up until I have this:
Code:
processes[process_count].setCPU_Burst(loc / 2, intbuff);
I've managed to isolate it specifically to when it trys to access the vector CPU_Burst[burst_loc] (and more than likely, with IO_Burst too, as that was copy-pasted from the CPU_Burst code). I'm completely stumped with this one... if someone could offfer some insight as to what I'm doing wrong, it would be appreciated... If I was to take a stab at it though, I'd say that CPU_Burst[loc] doesn't actually exist in the memory, despite the fact I've actually assigned it in the constructor. Thanks.