一直报错Const PCB cannot convert to *PCB

Keeping getting an error of Const PCB cannot convert to *PCB

我收到一条错误消息,指出 const PCB 无法转换为 *PCB,我可以将对象声明为 NULL 的唯一方法是使用指针。谁能帮我解决问题。我把//发生错误的地方我只是试图将最高优先级的进程控制块存储在 CPU 中,第一个 "if statement when it is NULL or empty" 和第二个将优先级队列的顶部与 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();
            }
        }
    }
}

您需要用您的代码修复一些问题,然后这会更清楚:

  1. 在您的 operator() 重载中将 PrCBk 更改为 PrCB
  2. 在您的 while 循环中将 While 更改为 while
  3. 您没有定义 operator==,每当您在 cpu.
  4. 等对象上使用 == 运算符时,这就会导致错误
  5. 一定要包括不同数据类型的运算符重载;即指针与引用。
  6. 查看 return 函数的值,例如 priority_queue.top() 并将 const_reference 与指针进行比较。确保您正确使用这些。

需要更正这些内容,以便您的代码可以编译。还有其他语法错误需要更正。