c++ - Simple error with the creation of a thread -


i try remember of how threads work, see c++11 simplify creation , utilisation of it. use answer post simple example of threading in c++ create simple thread.

but there's difference between me , answer of post, i'm not in main, create thread in constructor, , it's not same parameters.

here's simple code , try do:

i'm in class mainwindow.cpp :

//constructor mainwindow::mainwindow(qwidget *parent) :     qmainwindow(parent),     ui(new ui::mainwindow) {     // constructs new thread , runs it. not block execution.     thread t1(lancerserveur, null);     ui->setupui(this); } void mainwindow::lancerserveur(){     std::cout << "le serveur se lance"; } 

the errors :

expected ';' before 't1'  statement cannot resolve address of overloaded function thread t1(lancerserveur, null); 

i think parameters thread t1(lancerserveur, null); false.

could explain me how works ?

thanks.

you use std::cout, i'm assuming no using namespace std; or somewhere before thread. try std::thread.

try lambda std::thread t1([this](){this->lancerserveur();});

don't forget th1.join() before exiting constructor, else std::terminate called in thread destructor.

if thread in th1 run while, make class member variable , initialisation th1 = std::move(std::thread t1([this](){this->lancerserveur();})); in class destructor, th1.join();


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -