我正在尝试创建一个对象队列并稍后修改它们。由于创建队列只是在修改队列中的它们并删除它们后创建一个副本,因此它们消失了。所以我需要一个指向我的对象的指针队列来解决这个问题(或者我理解)。
我的课:
class process {
int waittime;
queue<int> cpuburst, iotime;
}
然后我像这样创建我的队列:
process *P1;
process *P2;
P1 = new process(//info to fill my P1 with data);
P2 = new process(//info to fill my P2 with data);
queue<process *> readyque;
queue<process *> onCPU;
readyque.push(P1);
readyque.push(P2);
编译得很好,但是当我尝试使用 .front() 或 .push() 对队列做任何事情时,我得到了错误C2228: left of '.cpuburst' must have class/struct/union
,并且我得到IntelliSense: expression must have class type
了“onCPU”的错误
在这条线上:
x = onCPU.front().cpuburst.front() + y;
我只是想让 x 等于我班级队列顶部的值,这也是我的 onCPU 队列的顶部