Passing user defined callback functions to a library method
A common solution would be to have the user provide a callback which
takes no arguments and returns nothing. This is how attachInterrupt()
works, so it may be the least surprising approach for your users. The
user function can then get data from the rest of the program using
globals.

If you really prefer passing an argument to the user function, the
problem is you do not know the data type. The usual approach in plain C
is to give it a “generic” pointer, and let the user cast it into a
pointer specific for his data type. This is how functions like qsort()
work:



HookNinja hookninja;

void userFunction(void *param) {
    someVariableType foo = * (someVariableType *) param;
    //do something with foo
}

void setup()
{
    hookninja.attachCallback(userFunction);
}

void loop() {
    someVariableType foo = something;
    hookNinja.process((void *) &amp;foo);
}


A cleaner C++ approach could be to make you class a template that is
specialized for the type of the user data:

HookNinja&lt;someVariableType&gt; hookninja;

void userFunction(someVariableType param) {
    //do something with param
}

void setup()
{
    hookninja.attachCallback(userFunction);
}

void loop() {
    someVariableType foo = something;
    hookNinja.process(foo);
}


But keep in mind that many Arduino users may not be familiar with
templates.