I simply have to overload square brackets in order for a program to work. I know the syntax for 1-dimensional array. It goes something like this:
class MyArray
{
private:
int *arr;
int size;
public:
MyArray(int s)
{
size = s;
arr = new int[size];
}
int & MyArray operator[](int); // declaring
};
int & MyArray :: operator[](int subscript)
{
assert(0 <= subscript && subscript <= size)
return arr[subscript];
}
void main()
{
MyArray a1(5);
a1[2] = 3;
}
I've included just the basic functions in this. This works fine. I just can't think of how to apply this to a double dimension array. I desperately need to overload [] for a 2 dimensional array. Can somebody please help?