how can I overload double subscript operator [][] in c++ ?
I have tried a number of ways.. No specific answer is available anywhere..
thanks in advance..
I have tried this.. But I know its not correct
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];
}
};