Hi team
Just playing around with C++11's multi-threading stuff, the follow code puzzle me, why my test1 below need double ()??
Here is the code:
Just playing around with C++11's multi-threading stuff, the follow code puzzle me, why my test1 below need double ()??
Here is the code:
C++:
/* -----------------------------------------
* MinGW-W64, v8.1.0
* Win10, 64-bit system
*------------------------------------------ */
#include <iostream>
#include <vector>
#include <string>
#include <thread>
using namespace std;
class test1
{
public:
void operator()()
{
for(int i = 0; i < 10; i++)
cout << "TEST1-" << i << endl;
}
};
class test2
{
public:
test2(int x):_x(x){}
void operator()()
{
for(int i = 0; i < _x; i++)
cout << "TEST2-" << i << endl;
}
private:
int _x;
};
int main()
{
std::thread threadObj1((test1())); // why double () here??, doesn't work without the double () eg: std::thread threadObj1(test1())
std::thread threadObj2(test2{10});
threadObj1.join();
threadObj2.join();
printf("done\n");
}
Last edited: