|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-02-09 13:17:05
Sergey Lukin wrote:
> Peter Dimov replied:
>
>>> t.async_wait(boost::bind(Component::Method1, &y, 10, boost::bind
>>> (DPC::Print1, &x, 2), &t));
>>
>> You need to prevent the inner bind from being treated as a
>> subexpression of the outer bind. Either assign it to a function<>:
>>
>> boost::function<void()> f = boost::bind( DPC::Print1, &x, 2 );
>> t.async_wait( boost::bind( Component::Method1, &y, 10, f ) );
>> or use boost::protect, as explained at the end of
>>
>> http://boost.org/libs/bind/bind.html#nested_binds
>
> I tried both suggested solutions but still have the same errors
>
> boost::function<void(int)> f = boost::bind( DPC::Print1, &x, 2 );
> t.async_wait( boost::bind( Component::Method1, &y, 10, f, &t ) );
> or
> t.async_wait( boost::bind( Component::Method1, &y, 10,
> boost::protect(f), &t ) );
Your Component::Method1 takes two arguments, three with the implicit 'this':
class Component
{
public:
template <typename Handler>
void Method1 (int x ,Handler h)
{
x++;
h();
}
};
but you are passing four, there is one extra &t at the end.
You should also use & with member functions, &Component::Method1, although
some compilers allow you to omit it.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk