Skip to content

Add MemberSlot#9

Open
michaelcowan wants to merge 1 commit into
masterfrom
add-member-slot
Open

Add MemberSlot#9
michaelcowan wants to merge 1 commit into
masterfrom
add-member-slot

Conversation

@michaelcowan

Copy link
Copy Markdown
Owner

Add MemberSlot

Submitted as a potential work around for issue #8

MemberSlot extends Slot and is designed to update references to member functions as they move or are copied.

e.g.

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

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

Popup copy = popup;

signal.emit();

Now, when emit is called, render() will be called on each instance of Popup

What has happened is that during the copy of MemberSlot, the callback function of show is recreated with a different value for this.

Calculating the value of this relies on the offset in bytes between the two MemberSlot instances being the same as the offset between the two Popup instances.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant