C++ overload operator [ ][ ]

后端 未结 5 1879
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 12:35

I have class CMatrix, where is \"double pointer\" to array of values.

class CMatrix {
public:
    int rows, cols;
    int **arr;
};

I simpl

5条回答
  •  抹茶落季
    2020-11-28 12:55

    If you create a matrix using Standard Library containers, it's trivial:

    class Matrix {
        vector> data;
    
    public:
        vector& operator[] (size_t i) { return data[i]; }
    };
    

提交回复
热议问题