我的这个堆栈的构造函数作为数组实现有什么问题?

What's wrong with my constructor for this stack as array implementation?

本文关键字:实现 数组 什么 问题 堆栈 构造函数 我的      更新时间:2023-10-16

下面的构造函数有什么问题?我收到一个错误,说:

错误

1 错误 C2359:非类类型的成员需要单个初始值设定项表达式
错误 2 错误 C2359:非类类型的成员需要单个初始值设定项表达式

它说错误在第 55 行,如果您快速查看,我将下面的字体设置为粗体。

template <typename Type>
class Drop_off_stack_as_array {
    private:
        int itop;
        int ibottom;
        int entry_count;
        int array_capacity;
        Type *array;
    public:
        Drop_off_stack_as_array( int = 10 );
        Drop_off_stack_as_array( Drop_off_stack_as_array const & );
        ~Drop_off_stack_as_array();
        int size() const;
        bool empty() const;
        Type top() const;
        bool full() const; 
        void swap( Drop_off_stack_as_array & );
        Drop_off_stack_as_array &operator = ( Drop_off_stack_as_array );
        void push( Type const & );
        Type pop();
        void clear();
    template <typename T>
    friend std::ostream &operator << ( std::ostream &, Drop_off_stack_as_array<T> const & );
};
template <typename Type>
Drop_off_stack_as_array<Type>::Drop_off_stack_as_array( int n ):
    itop(0),
    ibottom(0),
    entry_count(0),
    array_capacity(0,n),
    **array(new Type[array_capacity]){**
        //empty constructor
    }

错误是前面的一行,在这里:

array_capacity(0,n),

应该是

array_capacity(n),