使用类中的列表以c ++列出容器

时间:2013-11-04 05:51:59

标签: c++ list templates stl containers

我正在使用列表创建此模板Queue。我不明白列表部分的错误是什么。当我键入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 );

 }  

1 个答案:

答案 0 :(得分:1)

您的列表对象被定义为list<E>,但您正在尝试push_back类型为T的对象。