#define ROW 3
#define COL 4
class Matrix
{
private:
int mat[ROW][COL];
//.....
//.....
};
int main()
{
Matrix m;
int a = m[0][1]; // reading
m[0][2] = m[1][1]; // writing
}
I think directly it not possible to overload [][] .
I think i have to do it indirectly but how to implement it?
The easier solution is to use the operator() as it allows multiple parameters.
The easy way is that the first operator[] returns an intermediate object that the second operator[] returns the value from the array.