小编Mit*_*kar的帖子

C++ 中重载双下标运算符 [][]

如何在 C++ 中重载双下标运算符 [][] ?

我尝试了很多方法..没有任何具体的答案..

提前致谢..

我已经尝试过这个..但我知道它不正确

class Matrix {

    int row;
    int col;
    int ** values;
    int ptr;

    public:
        Matrix(const int r, const int c) {

            ptr = -1;
            row = r;
            col = c;

            values = new int*[row];

            for(int i=0; i<row; i++) {

                values[i] = new int[col];
            }
        }

        int & operator[](int p) {

            if(ptr == -1)
                ptr = p;

            return values[ptr][p];

        }

};
Run Code Online (Sandbox Code Playgroud)

c++ double overloading operator-keyword

0
推荐指数
1
解决办法
3928
查看次数

标签 统计

c++ ×1

double ×1

operator-keyword ×1

overloading ×1