mardi 3 mai 2016

Take multiple arguments to the thread function c++11

I have an array of threads and in forloop I should create a thread to all of them.

The problem is that one of the parameters is std::move(promise_var) and another one is structure. When I try to compile it compile gives me an error:

error: no matching function for call to ‘std::thread::thread(void (&)(Function), Structure [nNumThreads], std::remove_reference<std::promise<const char*>&>::type)’

So, here is the simplified version of code...

func(struct Structure, std::promise<const char *> && v_Promise){

 //doing work

}

main(){
 std::thread a_Threads[5];

 for(int8_t i = 0; i < 5; i++){

   a_Threads[i] = std::threads(func, Structure, std::move(v_promise));

 }
}

Aucun commentaire:

Enregistrer un commentaire