Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. I check, compile and run every program. Contact me at: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,032 questions

9,976 answers

573 users

How to create a thread using function objects in C++

1 Answer

0 votes
#include <iostream>
#include <thread>

using std::cout;
using std::endl;

class TestThread
{
public:
	void operator()()
	{
		for (int i = 0; i < 10; i++)
			cout << "operator()()" << endl;
	}
};

int main()
{
	std::thread obj( (TestThread()) );

	for (int i = 0; i < 4; i++)
		cout << "main()" << endl;

	cout << "Waiting For Thread to finish" << endl;

	obj.join();

	cout << "end main()" << endl;

	return 0;
}
/*
run:

operator()()
main()
main()
operator()()
main()
operator()()
main()
operator()()
Waiting For Thread to finish
operator()()
operator()()
operator()()
operator()()
operator()()
operator()()
end main()

*/

 




answered Feb 5 by avibootz
...