Skip to content

Instantly share code, notes, and snippets.

@leifbladt
Created November 29, 2012 06:56
Show Gist options
  • Save leifbladt/4167269 to your computer and use it in GitHub Desktop.
Save leifbladt/4167269 to your computer and use it in GitHub Desktop.
class Broker {
public:
void subscribe(void (*f)()) {
_f = f;
}
void notify() {
(_f)();
}
private:
void (*_f)();
};
class B {
public:
B(Broker* b) {
_b = b;
// error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&B::c'
// error: no matching function for call to 'Broker::subscribe(void (B::*)())'
// note: candidates are: void Broker::subscribe(void (*)())
_b->subscribe(&c);
}
void c() {}
private:
Broker* _b;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment