You probably know, but there are no such things as callback functions in C++. There are, however, function pointers.
Function pointers are literally that - pointers to functions. With "normal" pointers you specify the data type that the pointer points to (e.g. int *foo
, char *bar
...); function pointers work similarly in that you specify the signature of the function: void (*baz)(int)
. Notice that baz
is the name of the pointer in this case.
Without code I'm not sure how your timing system will work. The first thing that would come to mind would be a tick function which is called repeatedly. You can either call this function at regular intervals or measure the time between the function calls - in either case you know the time that has elapsed. Increment (or decrement) an allotted time variable, and when the time is up use the function pointer to trigger the "callback".
One thing you may find useful is typedef
ing your callback function like so:
typedef void (*Callback)(int)
(again, Callback
is the identifier). Then you can define a function like any other member (Callback func = foo
) and call it (func(12)
).
PS: There are good resources for function pointers dotted around SE. Here's one.