Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MemberSlot #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add MemberSlot #9

wants to merge 1 commit into from

Conversation

michaelcowan
Copy link
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.

None yet

1 participant