From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-04-01 23:33:29
On Monday 01 April 2002 08:17 pm, you wrote:
> The first argument has changed from OpaqueDataT * to
> boost::any. That does not work.
> //replacing the arg from OpaqueDataT * to boost::any
> gives error.
> boost::function<void, boost::any> f2 = yieldcallback;
> VC++ 6.0 issues the error:
>h pp(94) : error C2664: 'void (struct OpaqueDataT *)' :
> cannot convert parameter 1 from 'class boost::any' to
> 'struct OpaqueDataT *'
> What is the right way to handle this?
The problem is that boost::any cannot be implicitly converted to OpaqueData*,
so you'll need to perform the conversion explicitly. You can use boost::bind
to do this:
boost::function<void, boost::any> f2 =
This means that a call 'f2(cbdata)' becomes a call like
However, I think that this is not really what you want. I'm going to guess
that the argument that is send back to the callback (that, in this case, has
type 'OpaqueDataT*') is provided by the user along with the callback. In this
case boost::bind is the better solution, used like this:
boost::function<void> f3 = boost::bind(yieldcallback, cbdata);
Notice that f3 doesn't even take an argument, because the argument is a part
of what f3 will call. Also, you need not worry about casting from a
boost::any back to the appropriate callback data type, because cbdata is
already of the correct data type. A call like 'f3()' then becomes a call
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk