Hi everyone. I've recently been asigned a program where we are required to create a 2D array dynamically and then do stuff with it. We are not allowed to "cheat" and use the 1D method. in the constructor of my class i have defined the array as:
//GamePiece is a different user defined class, size is an integer passed to the constructor and handle is the name of the 2D array
handle = new GamePiece*[size];
for(i=0;i<size;i++)
{
handle[i] = new GamePiece[size];
}
In the constructor i have no problem accessing the values in the array with
handle[row][column]
but in any other function in this class i get an unhandled exception, access violation reading location 0x000000.... error. my quesiton is:
is this the correct way to access the values stored in the 2D array within this class or should i overload the () operator?
if i need to overload the () operator, do you have any suggestions on how to go about that? i know how to overload the =, and the <</>>, but i've never had to do the () before. while i'm sure it would be similar to the others, i'd appreciate a little direction if you don't mind. Thanks!