[Solved] No operator “==” matches these operands for sf::RectangleShape


There is no equality operator defined for the sf::RectangleShape class. You will need to create one, and decide on exactly what properties determine equality.

Perhaps size and position are what you care about. So you could define the following function:

bool operator==( const sf::RectangleShape & a, const sf::RectangleShape & b )
{
    return a.getSize() == b.getSize() && a.getPosition() == b.getPosition();
}

This would be okay, because both the getSize and getPosition member functions return a Vector2f which does have an equality operator. You might care about about getScale too.

Naturally, it’s up to you to determine what constitutes equality. The lack of an equality operator on the sf::RectangleShape is not surprising, given that it does a lot, including texturing etc. It’s obviously not the kind of thing you expect to be comparing with other objects.

See Reference for sf::Vector2f

1

solved No operator “==” matches these operands for sf::RectangleShape