Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-06-24 07:35:37


Jason wrote:
> I'm trying to use bind with boost.thread in order to make a thread of
> a class member function with an input argument, but I can't get it to
> compile. To narrow the problem, I went to the bounded_buffer.cpp
> program in the libs/thread/tutorial dir. I added an int arg to
> sender, and then changed boost::thread thrd1(&sender);
> to
> int x = 99;
> boost::thread thrd1(boost::bind<void>(&sender, _1)(x));

You need boost::bind(sender, x), assuming that sender is a void function
taking an int.

> I got this syntax from the bind doc
> (http://www.boost.org/libs/bind/bind.html). What am I doing wrong?

Hmm... the examples in the documentation bind and call on a single line in
order to demonstrate the effect of the various possibilities. It can be
confusing. :-) Your case is covered by the first sentence:

"bind(f, 1, 2) will produce a "nullary" function object that takes no
arguments and returns f(1, 2)."


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net