Say you have a class that has members
private:
double a,b,c,d,e,f,g,h,i;
You can make an accessor like:
double operator[](int index)
{
if(index == 0)
return a;
else if(index == 1)
return b;
else if(index == 2)
return c;
}
But how would you do something like this:
double operator[][](int rindex, int cindex)
{
if(rindex == 0 && cindex == 0)
return a;
else if(rindex == 1 && cindex == 0)
return b;
else if(rindex == 2 && cindex == 0)
return c;
else if(rindex == 0 && cindex == 1)
return d;
..... etc ...
}
The compiler doesn't like the above attempt. The behavior I'm looking for is:
MatrixClass Matrix;
// ... fill it
double test = Matrix[0][1];
Thoughts?
Thanks,
Dave