Class data being corrupted after passing it through a paramater???
I've spent hours narrowing my problem down to these few lines of code.
This is how my two dimensional array of classes is defined:
Code:
square board[8][8]; //Creates a 8x8 array of square objects
This is the function I'm using to change the array's elements.
Code:
void setBoard(square b[8][8])
{
int j;
vector <CP> wPawn(8,'W'); //defines a vector of 8 CP objects
vector <CP> bPawn(8,'B');
for (j=0;j<8;j++)
{
b[j][1].place(&wPawn[j]);
b[j][6].place(&bPawn[j]);
}
cout << b[1][1]; //tests this individual square's data : Outputs correctly (the char 'P')
pause(); //similar to a system pause
}
Where the strangeness comes in:
Code:
setBoard(board); //the function above
cout << board[1][1]; //tests this individual square's data : Outputs a seemingly random character ('=' O_o)
pause(); //similar to a system pause
When I output the whole array, the unchanged square objects output correctly. However, the ones that are changed inside of setBoard() become corrupted or something. Is there anything wrong with the way I'm passing that parameter? I've gotten away with doing it like this before.