0

I was making a chess engine and I have a list of moves.

std::list<Move> moves;

I also have a function that checks if the king is under a check after a specific move.

bool Board::check_after_move(const Move& move)
{
    Board temp=*this;
    temp.DoMove(move);
    return temp.check();
}

After I generate possible moves, I filter out the illegal ones.

moves.remove_if(check_after_move);

But I get an error

'&': illegal operation on bound member function expression

How should I fix this?

Edit: This is another error I get

'std::list<Move,std::allocator<Move>>::remove_if': no matching overloaded function found
Dino 1729
  • 37
  • 6

1 Answers1

3

check_after_move is a non-static member function, so you cannot make a basic function pointer from it.

The easiest general solution is to pass a lambda that captures this:

moves.remove_if([this](const Move& move) { return check_after_move(move); });

Or you can bind the this pointer directly:

moves.remove_if(std::bind(&check_after_move, this, std::placeholders::_1));
Asteroids With Wings
  • 17,071
  • 2
  • 21
  • 35