And you really need a solution, supposing positions are int :
if (abs(x - this->getLocX()) == abs(y - this->getLocY()))
{
int cx = this->getLocX();
int cy = this->getLocY();
int dx = (x > cx) ? 1 : -1;
int dy = (y > cy) ? 1 : -1;
while (cx != x)
{
cx += dx;
cy += dy;
if (boardP->hasPiece(cx, cy))
return true; // THERE ARE PLAYERS IN THE WAY
}
return false; // THERE ARE NO PLAYERS IN THE WAY
}
solved C++ check if there are players on the way in Chess game