jeudi 22 janvier 2015

boost thread with c++ 11lambda

How can I use boost thread with C++11 lambda?


The following code doesn't work:



int sum;
m_workerThread=new boost::thread([]()
{
for(int i=0;i<100;i++)
{
sum=sum+i;
}
}
);


I am getting compile error.



Error 4 error C3493: 'sum' cannot be implicitly captured because no default capture mode has been specified


How can I fix this?


Aucun commentaire:

Enregistrer un commentaire