错误第4行 和 (第53行):参见正在编译的类模板实例化'ArrayStack'的引用
#ifndef ARRAYSTACK
#define ARRAYSTACK
template <typename T>
class ArrayStack: public Stack<T>
{
private:
T* data;
int top;
int size;
public:
ArrayStack(){
top = 0;
data = new T[10];
size = 10;
}
~ArrayStack(){
delete[] data;
}
void push(const T &t){
if(top==size-1){
T* data2 = new T[(size*size)];
for(int i=0; i<size; size++){
data2[i] = data[i];
}
*data = *data2;
data[top+1] = t;
size= size*size;
top = top+1;
}
else{ data[top+1] = t; top = top+1;}
}
T pop() {
if(this.isEmpty==true){
throw std:: out_of_range " The stack is empty";
}
else{
return data[top];
top = top-1;
}
}
T peek() const{
return data[top];
}
bool isEmpty(){
if(top==0) return true;
else return false;
}
};
#endif
不确定为什么这会给我这个错误。新时间C ++编码器。任何帮助将不胜感激,谢谢! 编辑:对不起!忘了我的Stack标头
#ifndef STACK
#define STACK
template <typename T>
class Stack {
public:
virtual ~Stack() {}
virtual void push(const T &t) = 0;
virtual T pop() = 0;
virtual T peek() const = 0;
virtual bool isEmpty() const = 0;
};
#endif