c++ - 类和队列

标签 c++ class queue

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

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

我创建了队列 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/

相关文章:

c++ - 为 STL 排序算法定义 < - 运算符重载、仿函数或独立函数?

c++ - 缠绕式类型转换

c++ - 不兼容的类声明 c++

ios - 使用swift通过UI按钮创建对象实例

c++ - 引用类类型 vector 中对象的成员

c - 在 C 中管理结构队列的最佳方法是什么?

c++ - 继承成员函数指针

c++ - 哪个运算符重载已用于 ifstream 对象以评估为 bool 值

laravel - 自动运行 Laravel 队列

python - destroy() tkinter toplevel from queue 默默地失败(竞争条件?)