Skip to content

Cannot move or copy instance of a class exposing Slot without breaking callback #8

@michaelcowan

Description

@michaelcowan

The intended use of ass for class decoupling will not invoke the callback of the expected instance when copied or moved.

e.g.

class Popup {
public:
    Slot<> show = Slot<>(this, &Popup::render);
private:
    void render() {
        Popup * pointer = this;
    }
};

Popup popup;
Signal<> signal;
signal.connect(popup.show);

Popup movedPopup = std::move(popup);

signal.emit();

Here, calling emit() will trigger the instance of Slot belonging to movedPopup, which is as expected. However the value of this in the callback method render() will be that of popup.

This is because the callback function in Slot (which contains the this value of popup) was moved into the Slot instance in movedPopup - this is as intended for Slot copy/move semantics, but when that function contains a pointer to this we get unexpected results, like this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions