gpt4 book ai didi

c++ - 类和队列

转载 作者:行者123 更新时间:2023-11-28 07:02:03 26 4
gpt4 key购买 nike

我正在尝试弄清楚如何使用队列和类。

如何使用队列将信息插入此类?

我创建了队列 queue<Processes> PrinterDevices

我该如何将这个队列中的东西插入到一个类中或从中读取?

class Processes
{
public:
void setPID (int a)
{
PID = a;
}
int retrievePID()
{
return PID;
}
void setFilename (string input)
{
Filename = input;
}
string retrieveFilename()
{
return Filename;
}
void setMemstart (int a)
{
Memstart = a;
}
int retrieveMemstart()
{
return Memstart;
}
void setRW (char a)
{
rw = a;
}
int retrieveRW()
{
return rw;
}
void setFilelength (string input)
{
Filelength = input;
}
string retrieveFilelength()
{
return Filelength;
}
private:
int PID;
string Filename;
int Memstart;
char rw;
string Filelength;
};

最佳答案

queue<Processes> PrinterDevices;
Processess obj;
//Populate object through setter methods

将此对象添加到 queue PrinterDevices

`PrinterDevices.push(obj);`

同样你可以创建更多对象..遍历...

while(!PrinterDevices.empty())
{
Processes obj = PrinterDevices.front();
//Add code to use obj;
PrinterDevices.pop();//Remove the object from queue which is already used above
}

关于c++ - 类和队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22292439/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com