0

我正在使用列表创建此模板队列。我不明白列表部分的错误是什么。当我键入 listObject.push_back() 时,程序说没有找到任何成员函数。提前致谢

#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 );

 }  
4

1 回答 1

1

您的列表对象被定义为 a list<E>,但您试图 push_back 类型的对象T

于 2013-11-04T05:57:22.757 回答