[lambda] for thread bind
Hi there, I am playing with lambda. This following code works: ------------------------------------- void test_thread(std::string s) { cout << "string is" << s << endl; } boost::thread enquiry_thread(test_thread, s ); ------------------------------------- but the lambda version does not compile. Why? Thanks. ------------------------------------- #include"boost/lambda/lambda.hpp" #include"boost/lambda/bind.hpp" using namespace boost::lambda; void test_thread(std::string s) { cout << "string is" << s << endl; } std::string s("I am a string"); boost::thread inquiry_thread(bind(test_thread, _1)(s) );
Boost lzw wrote: [snip]
but the lambda version does not compile. Why? Thanks. -------------------------------------
void test_thread(std::string s) { cout << "string is" << s << endl; }
std::string s("I am a string"); boost::thread inquiry_thread(bind(test_thread, _1)(s) );
bind(test_thread, _1) creates a functor expecting one argument. Appending "(s)" right after invokes that functor, passing it s as an argument. What you want is: bind(&test_thread, s)
participants (2)
-
Boost lzw
-
Eric MALENFANT