Hey everyone, I'm having abit of trouble with a seg fault. As said in the topic, the piece of code that gives the error isn't really working with an array.
I ran the program through the gdb tool in g++, and it says the the seg fault occurs in the following function:
bool Board::ValidMove(int _y,char _x,Piece &MovingPiece)
{
if (MovingPiece.validateMove(_y,_x))
{
if ((_x >= 'a' && _x <= 'i') && (_y >= 0 && _y <= 8))
{
return true;
}
}
return false;
}
If it helps, this is the piece of code that calls this function:
void Board::Move(char Xin,char Xto, int Yin,int Yto)
{
Piece* Selected;
for(int Row = 0;Row < 9;++Row)
{
for(int Col = 0;Col < 9;++Col)
{
if (Player1Pieces[Col]->Y == Yin && Player1Pieces[Col]->X == Xin)
{
Selected = Player1Pieces[Col];
}
else if (Player2Pieces[Col]->Y == Yin && Player2Pieces[Col]->X == Xin)
{
Selected = Player2Pieces[Col];
}
}
}
if (ValidMove(Yto,Xto,*Selected))
{
Selected->X = Xto;
Selected->Y = Yto;
}
else
cout << "Invalid move, try again." << endl;
}
"Player1Pieces" and "Player2Pieces" are double-pointer(**) arrays.
Would be nice if someone could help me continue with my program :)