mardi 28 avril 2015

C++ universal function caller

I'd want to implement a function caller that works just like the thread constructor. For example

std::thread second (bar,0);

will start a thread which calls bar with the single argument 0. I would like to do the same thing, but I do not know how.

For example, given:

void myFunc(int a){
    cout << a << endl;
}

I would like:

int main() {
    caller(myFunc,12);
}

to call myFunc with the parameter 12.

Aucun commentaire:

Enregistrer un commentaire