2013-11-04 17 views
0

我使用列表创建此模板队列。我不明白错误是关于列表部分的。当我输入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); 

} 
+0

好的,你*将'T'推到'E'列表中。 – chris

回答

1

你的列表对象定义为一个list<E>,但你要的push_back T类型的对象。

+0

谢谢。但即使我纠正它,当我键入listObject。该程序说没有可用的成员函数。 – user2419831

+0

“程序”是编译器,你应该粘贴确切的错误信息。 –

+0

当你说“该程序没有提供任何成员函数”时,我不明白你的意思。我将你的代码复制到一个文件中,修复了一些语法错误,然后它编译了w/o错误。 –