-
-
Save cfeckardt/6750542 to your computer and use it in GitHub Desktop.
This file contains 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
class Example { | |
someAsyncronousMethod(void * completed ) { | |
// This methods takes a long time, and runs on a separate thread so that it doesn't block execution. | |
// When we are done ... | |
if(completed != NULL) | |
(*completed)(); | |
} | |
} | |
void foo() { | |
std::cout << "Our long running method has completed." | |
} | |
int main(int argc, char ** argv) { | |
Example ex; | |
void * foo = &foo | |
ex.someAsyncronousMethod(fooPtr); | |
while(true) { | |
//Event loop | |
} | |
return 0; | |
} |
This file contains 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
class MyWindow : Window | |
{ | |
Button _button; | |
public MyWindow() | |
{ | |
_button = new Button(); | |
// place the button in the window | |
_button.Click += MyWindow.ButtonClicked; | |
} | |
static void ButtonClicked(object sender, RoutedEventArgs e) | |
{ | |
MessageBox.Show("Button Clicked"); | |
} | |
} |
This file contains 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
// The callback interface | |
interface MyCallback { | |
void callbackCall(); | |
} | |
// The class that takes the callback | |
class Worker { | |
MyCallback callback; | |
void onEvent() { | |
callback.callbackCall(); | |
} | |
} | |
// Option 1: | |
class Callback implements MyCallback { | |
void callbackCall() { | |
// callback code goes here | |
} | |
} | |
worker.callback = new Callback(); | |
// Option 2: | |
worker.callback = new MyCallback() { | |
void callbackCall() { | |
// callback code goes here | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment