c++ class method as callback code example
Example: c++ callback member function
class Foo {
int (*func)(int);
public:
void setCallback( int (*cFunc)(int) ) {
func = cFunc;
}
void set() {
setCallback(callback); // Set callback function to be called later
}
void use() {
func(5); // Call the previously set callback function
}
// Note the 'static'
static int callback(int param) {
return 1;
}
};