c2955 Error - Use of Class template reuires argument list

后端 未结 1 645
闹比i
闹比i 2021-01-23 16:52

So, I\'ve tested vector and it seems to be running fine. However, I\'m trying to implement a basic Stack class built off of my Vector class. I keep running into these errors whe

相关标签:
1条回答
  • 2021-01-23 17:17

    You have defined Vector<T> as a member of Stack already, it's not necessary to inherit from Vector

    Update

    template <class T>
    class Stack : public Vector{       
       //...
    };
    

    To:

    template <class T>
    class Stack {
       Vector<T> stack;   
       //...
    };
    

    Or if you want to inherit from a template class, you need to provide template parameter

    template <class T>
    class Stack : public Vector<T>{
    //                         ^^^
    

    Note:

    You miss a few semicolons in Stack function definition and a bug in Stack::push_back as well, I may suggest update to below:

    template <class T>
    class Stack 
    {
    private:
        Vector<T> stack;
    public:
        Stack(){};
        void push(T const& x) {stack.push_back(x);}
        void pop(){stack.pop_back();}
        bool empty(){return stack.empty();}
    
    };
    
    0 讨论(0)
提交回复
热议问题