我使用列表创建此模板队列。我不明白错误是关于列表部分的。当我输入listObject.push_back()时,程序说没有找到成员函数。在此先感谢使用类别列表列出C++中的容器
#include <iostream>
#include <list>
using namespace std;
template<class T, class E>
class Queue{
public:
// Creates a Queue with an initial capacity of 10
Queue();
//Creates a Queue object with an initial capacity of size cap
Queue(int cap);
//adds item to the end of the queue
void add(T item);
//returns true if the queue is empty
bool isEmpty() const;
//removes the front item from the qeue
T remove();
//Provide a copy of the object that is first in the queue
T first() const;
//updates the item in the front of the queue
void updateFirst(T item);
//output all information currently stored in the queue
friend ostream& operator<<(ostream& out, const Queue<E>& obj)
private:
list<E> listObject;
int capacity;
};
template<class T, class E>
Queue<T,E>::Queue()
{
capacity = 10;
}
template<class T, class E>
Queue<T,E>::Queue(int cap)
{
capacity = cap;
}
template<class T, class E>
void Queue<T,E>::add(E item)
{
listObject.push_back(item);
}
好的,你*将'T'推到'E'列表中。 – chris