#include <iostream>
#include <thread>
class f
{
public:
f(int i = 0, std::string s = "") : _i(i), _s(s) { }
void operator()() const
{
for(int i = 0; i < _i; ++i)
std::cout << _s << std::endl;
}
int _i;
std::string _s;
};
int main()
{
//std::thread t1(f()); // Most vexing parse (Scott Meyers: Effective STL)
std::thread t2((f(3, "Hello"))); // OK
//t1.join(); // prog.cpp:23:5: error: request for member 'join' in 't1',
// which is of non-class type 'std::thread(f (*)())'
t2.join();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dGhyZWFkPgoKY2xhc3MgZgp7CnB1YmxpYzoKICAgIGYoaW50IGkgPSAwLCBzdGQ6OnN0cmluZyBzID0gIiIpIDogX2koaSksIF9zKHMpIHsgfQogICAgdm9pZCBvcGVyYXRvcigpKCkgY29uc3QKICAgIHsKICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCBfaTsgKytpKQogICAgICAgICAgc3RkOjpjb3V0IDw8IF9zIDw8IHN0ZDo6ZW5kbDsKICAgIH0KICAgIGludCBfaTsKICAgIHN0ZDo6c3RyaW5nIF9zOwp9OwoKCmludCBtYWluKCkKewoJLy9zdGQ6OnRocmVhZCB0MShmKCkpOyAgICAgICAgICAgIC8vIE1vc3QgdmV4aW5nIHBhcnNlIChTY290dCBNZXllcnM6IEVmZmVjdGl2ZSBTVEwpCglzdGQ6OnRocmVhZCB0MigoZigzLCAiSGVsbG8iKSkpOyAgLy8gT0sKCS8vdDEuam9pbigpOyAgLy8gcHJvZy5jcHA6MjM6NTogZXJyb3I6IHJlcXVlc3QgZm9yIG1lbWJlciAnam9pbicgaW4gJ3QxJywgCgkgICAgICAgICAgICAgIC8vIHdoaWNoIGlzIG9mIG5vbi1jbGFzcyB0eXBlICdzdGQ6OnRocmVhZChmICgqKSgpKScKCXQyLmpvaW4oKTsKCXJldHVybiAwOwp9