Mit*_*kar 0 c++ double overloading operator-keyword
如何在 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)