Created
June 5, 2020 21:20
-
-
Save jmlyn/51f8582fcce978ca775e73b0e1da8561 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Example program | |
| #include <iostream> | |
| #include <string> | |
| #include <vector> | |
| #include <functional> | |
| class Event { | |
| public: | |
| void Subscribe(std::function<void(void)> fn) { | |
| mSubscribers.emplace_back(fn); | |
| } | |
| void Raise() { | |
| for (auto subscriber : mSubscribers) { | |
| subscriber(); | |
| } | |
| } | |
| private: | |
| std::vector<std::function<void(void)>> mSubscribers; | |
| }; | |
| int main() | |
| { | |
| Event onNavigationDone; | |
| onNavigationDone.Subscribe([]() { | |
| std::cout << "Function called!" << std::endl; | |
| }); | |
| onNavigationDone.Raise(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment