0

i am mostly familiar with java and c++ is not my strong spot..

I am trying to write algorithm for cpu scheduler most of my code is syntax error free but I am stuck to one problem.

My program uses 2 classes Process and ProcessQueue

my main looks like this

int main(){

    fstream f;

    ProcessQueue pq;

    f.open("input.txt");

    if (!f)
    {
        cout << "File not Found";
    }else{
    int noOfProcess;

    f >> noOfProcess;
    Process *p;
    p = new Process[noOfProcess];

    for (int i = 0;i<noOfProcess;i++){
        int arivalTime;
        int cpuTime;
        int prorityNumber;

        f >> arrivalTime;
        f >> cpuTime;
        f >> prorityNumber;

        p[i] = new Process(arrivalTime,cpuTime,prorityNumber);
    }
return 0;
}

but p[i] is causing trouble.. I am not able to use parametric constructor,setters.

it gives following error

enter image description here

1
  • 1
    The variable p doesn't point to an array of pointers, but an array of objects. Try p[i] = Process(...) (without the new keyword). Commented Nov 13, 2016 at 10:46

1 Answer 1

2

Change

p[i] = new Process(arrivalTime,cpuTime,prorityNumber);

to

p[i] = Process(arrivalTime,cpuTime,prorityNumber);

as p[pi] is of type Process

Also use std::array or str::vector

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.