In addition to function pointers and class function objects that may interest you in the new C ++ 0x iamba.
Here is an example of passing a lambda to a timer function.
#include <windows.h>
#include <iostream>
#include <functional>
void onInterval(DWORD interval, std::function<void ()> callback) {
for (;;) {
Sleep(interval);
callback();
}
}
int main() {
onInterval(1000, []() {std::cout<<"Tick! ";});
}
source
share