Launching thread by using function object as callable

  • Thread starter Thread starter Jeff0803
  • Start date Start date
J

Jeff0803

Guest
Here is the sample code to launch thread.

#include <iostream>
#include <thread>
using namespace std;

// A callable object
class thread_obj {
public:
void operator() (int x)
{
for (int i = 0; i < x; i++)
{
cout << "Thread using function"
" object as callable\n";
}
}
};

int main()
{
thread th1(thread_obj(), 3);

th1.join();
return 0;
}


What I don't understand is following line in the thread_obj class.

void operator () (int x)

I can't figure out what this means and how th1 call this.

Is this operator overloading?

Can anybody explain about this?

Continue reading...
 
Back
Top