0
我得到的是说const的PCB不能转换的错误* PCB,我可以声明对象为NULL的唯一方法是使用指针。任何人都可以帮我弄清楚这个问题。我把/ /错误发生的地方我只是试图存储CPU中的最高优先级过程控制块为第一个“如果语句时,它是NULL或空”,第二个比较优先级队列的顶部cpu,如果ready_queue.top高于cpu,则抢占它。使用试过布尔的isEmpty()和其他的事情,但似乎没有任何工作饲养越来越常量PCB的错误不能转换为* PCB
struct PrCB
{
int PrID;
int PrSize;
int prior;
int sumMem= 0;
bool operator < (const PrCB & a)
{
return prior < a.prior;
}
bool operator > (const PrCB & a)
{
return prior > a.prior;
}
};
struct compare
{
bool operator()(const PrCB &a,const PrCB &b)
{
return a.prior < b.prior;
}
};
int main()
{
int pid = 0;
char inter;
PrCB pcb;
PrCB cpu;
priority_queue<PrCB, vector<PrCB>,compare> ready_queue;
while(true)
{
cin >> inter;
if(inter == 'N')
{
pcb.PrID = pid;
cout << "How much memory space?" << endl;
cin >> pcb.PrSize;
cout << "What is the Priority?" << endl;
cin >> pcb.prior;
ready_queue.push(pcb);
pid++;
//if(cpu == NULL)
{
cpu == ready_queue.top();
ready_queue.pop();
}
//if(cpu < ready_queue.top())
{
ready_queue.push(cpu);
//cpu = ready_queue.top();
ready_queue.pop();
}
}
}
}
因此,如果我要做一个布尔运算符==(PrCB&a)如果(a.priority == NULL)返回一些东西?我不明白你的意思是由priority_queue.top()或你的意思是ready_queue.top()?谢谢您的帮助 ! – user58504
'a.priority'的类型为'int',这意味着您不需要检查'NULL'。我认为你可能会对什么是指针和什么不是,“int”不是指针感到困惑。 'ready_queue'的类型是'priority_queue',所以你可以读作'ready_queue.top()'。 – user2205930
ahhh好,所以如果我们使布尔运算符==(PrCB&a)那是假设返回什么因为我想要使用if(cpu ==空或NULL)将ready_queue.top()移动到cpu,这是我有什么麻烦:S – user58504