Button click logic with SFML
Compile with all warnings  


If you compile this code with all warnings enabled (e.g. -Wall -Wextra -pedantic) the compiler will tell you that your initialization is out of order.
This simply means you initialize your members in a different order than they have been declared in. In your example this is not bad but if you have members that depend on others being initialized before them this can lead to problems.


&amp; is part of the type in C++


While this is not an error it can look like bitwise AND at a glance and be a potential source of confusion. Prefer to write foo&amp; bar instead of foo &amp; bar.


User defined types


Also just a minor nitpick but usually user defined types start with an uppercase letter i.e. ClickableRect.
Since you inherit from Shape I think it would make more sense to name your class ClickableShape but this is just personal preference.


Design


You expose window to your class only to get access to the mouse coordinates. Unless you plan to use window in a different matter in the future it'd be better to hide this info from your class.
A simple approach to testing for a click within your shape could be:

class ClickableShape : public sf::RectangleShape {
public:
    bool click(const sf::Vector2i&amp; mouse_pos) const {
        return getGlobalBounds().contains(mouse_pos.x, mouse_pos.y);
    }
};


Which can then be called as:

ClickableShape cs{};
cs.setSize(sf::Vector2f(50, 50));
cs.setFillColor(sf::Color(0xffffffff));


And finally in your event loop:

case sf::Event::MouseButtonPressed:
    cs.click(sf::Mouse::getPosition(window));
    break;


This way you avoid exposing unnecessary data to your class and can still check if the shape was clicked.

Approach #2:

I'm not sure what you're planning to do with this in the future but another approach to this would be to keep the inheritance short and have the rectangle as a member.

class MyButton : public sf::Drawable {
public:
    MyButton() {
        shape.setSize(sf::Vector2f(50, 50));
        shape.setFillColor(sf::Color(0xffffffff));
    }

    bool click(const sf::Event&amp; event) const {
        return shape.getGlobalBounds().contains(event.mouseButton.x, event.mouseButton.y);
    }

    void draw(sf::RenderTarget&amp; target, sf::RenderStates states) const {
        target.draw(shape);
    }

private:
    sf::RectangleShape shape;
};