I have a pointer called **pieces that points to an array of class type GamePieces that contain members pName and pType. I am trying store values in pieces[row][col].pType and then print the pieces in a matrix. My program crashes on this line of code:
while (pieces[row][col].pType == 'X' || pieces[row][col].pType=='O') {
Here's the code for the function:
void GameBoard::AssignPlayer1(int row, int col, GamePiece& p1)
{
while (pieces[row][col].pType == 'X' || pieces[row][col].pType=='O') {
cout << "Space is already taken, try again" << endl;
cout << "row: ";
cin >> row;
row -= 1;
cout << "column: ";
cin >> col;
col -= 1;
cout << endl << endl;
}
strcpy(&pieces[row][col].pType, &p1.pType);
}
Here's my print to screen function and my operator overload:
void GameBoard::RefreshBoard()
{
int row;
int col;
for (row=0; row < size; row++) {
for (col=0; col < size; col++) {
cout << &pieces[row][col].pType;
}
cout << endl;
}
cout << endl << endl;
}
ostream& operator<<(ostream& os, const GamePiece& p)
{
os << " " << p.pType << " " << endl;
return os;
}
??????? What's wrong????