Callback Timer function in C++ -


i trying implement callback timer function in c++ should callback after timeout. listening on socket , waiting messages on it. if have getmessages() , want pass timer function in argument. how can implemented after receive of message, timer started , callback happens if there timeout before next messages arrives.

i new callback functions. appreciated. thanks!

you know, there no such things callback functions in c++. there are, however, function pointers.

function pointers literally - pointers functions. "normal" pointers specify data type pointer points (e.g. int *foo, char *bar...); function pointers work in specify signature of function: void (*baz)(int). notice baz name of pointer in case.

without code i'm not sure how timing system work. first thing come mind tick function called repeatedly. can either call function @ regular intervals or measure time between function calls - in either case know time has elapsed. increment (or decrement) allotted time variable, , when time use function pointer trigger "callback".

one thing may find useful typedefing callback function so: typedef void (*callback)(int) (again, callback identifier). can define function other member (callback func = foo) , call (func(12)).

ps: there resources function pointers dotted around se. here's one.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -