Declaring an array inside a class, and setting its size with the constructor

前端 未结 5 615
陌清茗
陌清茗 2020-12-19 05:48

I haven\'t worked with c++ in a while, but I just started a project with it. This may not be possible, but Im trying to create a template class with an array that sets its s

5条回答
  •  执笔经年
    2020-12-19 06:31

    std::vector is precisely the tool for this job:

    template
    class Tarray {
    private:
        std::vector this_array;
    public:
        Tarray(int s): this_array(s){
        }
        ~Tarray(){
        }
        T & operator[](int i){
            return this_array[i];
        }
    };
    

提交回复
热议问题