ok Thank you.. that makes sense. I have some rudimentary knowledge of operator overloading already.
All arrays I'm using are 2D. For example, in my world class, I'm trying to build a constructor that looks like this..
World::World()
{
for (int i = 0; i <= 19; i++)
{
for (int j = 0; j <= 19; j++)
{
//creates an empty array
}
}
//calls fillGrid();
}
So in the operator overload function body, can I just do something like this which, to me, seems to say "Whenever you encounter an instance of these guys [], do the following.."? int& ClassName::operator[]( int indx ) {
if( indx < 0 || indx >= size ) {
//some error handling
exit(-1);
}
return data[indx];
}
I found the above snippet online but the example of this overload worked with a class that only used lists, not grids.
Thanks again..
Ella