2

错误第 4 行 AND(第 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++ 编码器。任何帮助将不胜感激,谢谢!编辑:对不起!忘记了我的堆栈标题

    #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
4

0 回答 0