C++ 以c++,在类中使用列表
我正在使用列表创建此模板队列。我不明白列表部分的错误是什么。当我键入listObject.push_back()时,程序会说找不到任何成员函数。提前谢谢C++ 以c++,在类中使用列表,c++,list,templates,stl,containers,C++,List,Templates,Stl,Containers,我正在使用列表创建此模板队列。我不明白列表部分的错误是什么。当我键入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
#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 );
}
#包括
#包括
使用名称空间std;
模板
类队列{
公众:
//创建初始容量为10的队列
队列();
//创建初始容量为大小上限的队列对象
队列(int cap);
//将项添加到队列的末尾
无效添加(T项);
//如果队列为空,则返回true
bool isEmpty()常量;
//从QUE中删除前面的项
T删除();
//提供队列中第一个对象的副本
T第一()常数;
//更新队列前面的项目
无效更新第一项(T项);
//输出当前存储在队列中的所有信息
friend ostream&operator您的列表对象被定义为一个列表
,但您试图将T
类型的对象推回T好吧,您正在将T
推到E
s列表上。谢谢。但即使我更正了它,当我键入listObject时。程序说没有可用的成员函数。“程序”是编译器,你应该粘贴准确的错误消息。我不明白你说“程序说没有可用的成员函数”是什么意思。我将你的代码复制到一个文件中,修复了几个语法错误,然后它编译了w/o错误。我明白了。谢谢大家。