mercredi 25 février 2015

Arguments in std::thread. How works?

Examples of use std::thread constructor:



#include <thread>
using namespace std;

void a_function(){}
void a_function2(int a){}
void a_function3(int a,int b){}
void a_function4(int &a){}

class a_class
{
public:
void a_function5(int a){}
};

int main()
{
a_class aux;
int a = 2;

thread t(a_function);
thread t2(a_function2,2);
thread t3(a_function3,2,3);
thread t4(a_function4,ref(a));
thread t5(&a_class::a_function5,&aux,2);

t.join();
t2.join();
t3.join();
t4.join();
t5.join();
}


How can constructor knows number of arguments? How can constructor calls one unknown type of function? How could i implement something like that? By example, one wrapper for std::thread



class wrapper_thread
{
thread t;

public:

wrapper_thread() //what arguments here?
: t() //What arguments here?
{}
}

Aucun commentaire:

Enregistrer un commentaire