[英]C++ Queue Implementation Error
I am trying to make a basic queue. 我正在尝试建立一个基本队列。 My header file is as follows: 我的头文件如下:
#ifndef Queue_h
#define Queue_h
/**
A simple Queue data structure
*/
template <class T>
class Queue{
public:
Queue(int s){
size = s > 0 && s < 1000 ? s : 10;
top = -1;
queuePtr = new T[size];
}
~Queue(){
delete[] queuePtr;
}
bool isEmpty(){
return top == -1;
}
bool isFull(){
return top == size - 1;
}
void push(const T){
if(!isFull()){
queuePtr[++top] = T;
}
}
T pop(){
if(!isEmpty()){
return queuePtr[top--];
}
}
private:
int size;
int top;
T* queuePtr;
};
#endif
I am getting the following error message 我收到以下错误消息
Queue.h: In member function 'void Queue<T>::push(T)':
Queue.h:30: error: expected primary-expression before ';' token
I am unsure why the expressoin shown is not considered a primary-expression. 我不确定为什么所显示的表达不被视为主要表达。 Any help or links would be appreciated Thanks in advance! 任何帮助或链接将不胜感激提前感谢!
You're treating a type ( T
) as a variable. 您将类型( T
)视为变量。 The code 编码
void push(const T){
if(!isFull()){
queuePtr[++top] = T;
}
}
should be 应该
void push(const T& item){
if(!isFull()){
queuePtr[++top] = item;
}
}
or something like that. 或类似的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.