In my opinion, it would make more sense to use regular getter functions that provide more indirect access to the array, instead of turning a reference to the whole private array itself. This promotes better encapsulation.
Code:
class MyClass
{
public:
int array[5][5];
public:
MyClass() { /* ... */ }
int& getArray(std::size_t index_x, std::size_t index_y)
{ return array[index_x][index_y]; }
/* And a const version: */
const int& getArray(std::size_t index_x, std::size_t index_y) const
{ return array[index_x][index_y]; }
};
int main()
{
MyClass obj;
const MyClass c_obj;
obj.getArray(0,0) = 1;
c_obj.getArray(0,0) = 1; // Error: assignment of read-only location
}
You can even use the getter functions to do bounds-checking when accessing the array, to make code safer.