dimanche 21 janvier 2018

Templatize functionpointer with default argument

I want to templatize that code below:

void attachHelpfunctionPointer(void (* functionPointer)(int),  int test=0);
void (* helpFunctionPointer)(int);

void attachHelpfunctionPointer(void (* functionPointer)(int), int test) {
    helpFunctionPointer = functionPointer;   //pass the address
}

and then somewhere later in the code call it:

attachHelpfunctionPointer(testFunctionXY, testValue);  //attach new function with argument
helpFunctionPointer (test);   //pass the argument

how can I replace the type "int" by a template of type "T"?

Aucun commentaire:

Enregistrer un commentaire