首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >继续获取Const PCB的错误不能转换为*PCB

继续获取Const PCB的错误不能转换为*PCB
EN

Stack Overflow用户
提问于 2016-11-27 20:16:40
回答 1查看 61关注 0票数 0

我得到了一个错误,说明const不能转换为*PCB,唯一可以声明对象为NULL的方法是使用指针。有人能帮我解决这个问题吗。我把//错误发生在哪里,我只是尝试在cpu中存储第一个“空或空时的if语句”的最高优先级进程控制块,第二个比较优先级队列的顶部与CPU,如果ready_queue.top大于cpu,则抢占它。已经尝试过使用bool isEmpty()和其他东西,但是似乎什么都没有用

代码语言:javascript
复制
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();
            }
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-27 21:24:05

您需要用代码修复几个问题,然后就会更加清楚了:

  1. operator()重载中,将PrCBk更改为PrCB
  2. 在while循环中,将While更改为while
  3. 您没有定义operator==,当您在cpu之类的事情上使用==运算符时,这会导致错误。
  4. 确保包含针对不同数据类型的操作符重载;即指针与引用。
  5. 查看像priority_queue.top()这样的函数的返回值,并将const_reference与指针进行比较。确保您正确地使用了这些。

这些事情需要纠正,以便您的代码编译。还有其他语法错误需要纠正。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40833424

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档