Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<class Sender>
- class Event {
- private:
- Sender *s;
- friend Sender;
- protected:
- event(Sender *s) : s(s) {}
- void operator() { }
- public:
- // register a function for the event
- void operator +=(void (*f)(Sender*)) { }
- // deregister a function from the event
- void operator -=(void (*f)(Sender*)) { }
- }
- class InternetConnectionListener {
- public:
- Event<InternetConnectionListener> onConnectionUp;
- Event<InternetConnectionListener> onConnectionDown;
- private:
- void someMethodThatGetsCalledWhenNetworkStateChanges() {
- if (networkIsUp) {
- // only this class is allowed to execute the () operator
- onConnectionUp();
- } else {
- onConnectionDown();
- }
- }
- }
Add Comment
Please, Sign In to add comment