++ - (.. , operator()). , , , , . , boost:: bind / < > , , .
, :
typedef void (*cb)(void*);
void funcThatNeedsCallback(cb thecallback, void *thedata) {
thecallback(thedata);
}
:
template<typename T>
void funcThatNeedsCallback(T &thefunctor) {
thefunctor();
}
:
struct MyFunctor {
int mydata1;
char *mydata2;
void operator()(void) {
}
};
MyFunctor mf = { value1, value2 };
funcThatNeedsCallback(mf);
, , .
(, funcThatNeedsCallback - , ), , , :
class CallbackInterface {
virtual void theCallback(void) = 0;
virtual ~CallbackInterface() {}
};
void funcThatNeedsCallback(CallbackInterface &cb) {
cb.theCallback();
}