我正在编写一个程序,它是由多用户计算机的CPU模拟服务作业。我已经定义了一个名为job
的类,我创建了两个这种类型的队列,一个是waitQueue
,另一个是CPUqueue
。我正在尝试使用CPUqueue
中的数据填充waitQueue
,并将其从waitQueue
中弹出并将其推送到CPUqueue
- 这就是目标,但是。我似乎无法写出这部分而没有错误地说error: request for member ‘push’ in ‘waitQueue’, which is of non-class type ‘std::queue<job> [10]’
(同样对于其他函数调用也是如此。请帮助..!
这是我一直在研究的main.cpp文件:
#include <iostream>
#include <string>
#include <stdlib.h>
#include <queue>
#include "job.cpp"
using namespace std;
int main()
{
int second = 0, jobsCompleted = 0, jobsToComplete = 0, probUser = 0, probability;
long id;
jobType_t job_type;
int inWQ, outWQ, inCPUQ, outCPUQ, required, given, jobTypeInt;
queue<job> CPUqueue[10], waitQueue[10];
srand(time(NULL));
cout << "Enter how many jobs need to be completed: ";
cin >> jobsToComplete;
cout << endl << "Enter the probability that a new job is created: ";
cin >> probUser;
cout << endl;
while(jobsCompleted < jobsToComplete)
{
second++;
probability = rand() % 100 + 1;
if(probability > probUser)
{
cout << "Enter new JOB ID: ";
cin >> id;
jobTypeInt = rand() % 1 + 1;
if(jobTypeInt = 1) job_type = IO_bound;
else job_type = CPU_bound;
required = rand() % 10;
inWQ = second;
job *newJob = new job(id, job_type, inWQ, outWQ, inCPUQ, outCPUQ, required, given);
waitQueue.push(newJob);
}
while(!CPUqueue.isFull())
{
waitQueue.back();
job *temp = waitQueue.pop();
CPUqueue.push(temp);
}
}
return 0;
}
谢谢!
答案 0 :(得分:3)
queue<job> CPUqueue[10], waitQueue[10];
这将创建两个包含10个队列的数组。它可能不是你想要的。
尝试:
queue<job> CPUqueue, waitQueue;
答案 1 :(得分:0)
你有一个队列数组,而不是队列,推送不适用于数组。
答案 2 :(得分:0)
除了@ otibom的回答:
non-class type ‘std::queue<job> [10]’
意味着:waitQueue
被声明为数组。数组中的对象是queue
s,但可验证的不是。