c2955 Error - Use of Class template reuires argument list

后端 未结 1 646
闹比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条回答
  •  猫巷女王i
    2021-01-23 17:17

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

    Update

    template 
    class Stack : public Vector{       
       //...
    };
    

    To:

    template 
    class Stack {
       Vector stack;   
       //...
    };
    

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

    template 
    class Stack : public Vector{
    //                         ^^^
    

    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 Stack 
    {
    private:
        Vector stack;
    public:
        Stack(){};
        void push(T const& x) {stack.push_back(x);}
        void pop(){stack.pop_back();}
        bool empty(){return stack.empty();}
    
    };
    

    0 讨论(0)
提交回复
热议问题