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