我得到了一个错误,说明const不能转换为*PCB,唯一可以声明对象为NULL的方法是使用指针。有人能帮我解决这个问题吗。我把//错误发生在哪里,我只是尝试在cpu中存储第一个“空或空时的if语句”的最高优先级进程控制块,第二个比较优先级队列的顶部与CPU,如果ready_queue.top大于cpu,则抢占它。已经尝试过使用bool isEmpty()和其他东西,但是似乎什么都没有用
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();
}
}
}
}发布于 2016-11-27 21:24:05
您需要用代码修复几个问题,然后就会更加清楚了:
operator()重载中,将PrCBk更改为PrCB。While更改为while。operator==,当您在cpu之类的事情上使用==运算符时,这会导致错误。priority_queue.top()这样的函数的返回值,并将const_reference与指针进行比较。确保您正确地使用了这些。这些事情需要纠正,以便您的代码编译。还有其他语法错误需要纠正。
https://stackoverflow.com/questions/40833424
复制相似问题