On Aug 28, 2:18*pm, Giovanni Gherdovich
<gherdov...@students.math.unifi.it> wrote:
> Hello,
>
> in the following code I have a pointer (to function), say p,
> of type
> double (*)(double, double, void*)
> and I try to fix the second argument of the function *p
> to a given value (using boost::bind), but the compiler
> complains, because of a type mismatch in an assignment
> which I think should be legal:
>
> /*
> ** *bash-3.00$ g++ function.cpp
> ** *function.cpp: In function `int main()':
> ** *function.cpp:36: warning: taking address of temporary
> ** *function.cpp:36: error: cannot convert
> ** * * * * `boost::_bi::bind_t<double,
> ** * * * * * * * * * * * * * * double (*)(double, double, void*),
> ** * * * * * * * * * * * * * * boost::_bi::list3<boost::arg<1>,
> **
> boost::_bi::value<double>,
> ** * * * * * * * * * * * * * * * * * * * * * * * boost::arg<2> > >*'
> ** * * * * * to `double (*)(double, void*)' in assignment
> **/
>
The compiler message says that the result of boost::bind is not
convertible to a function pointer.
boost::bind is a function template which returns an object (the type
of this object is a function of the parameters passed to the
boost::bind invocation), not an "ordinary" function.
The warning about taking the address of a temporary is because your
code takes the address of that object returned by boost::bind.
> How can I build a "real" (I mean non-temporary) object
> out of boost::bind( ... ), so that its address can
> be passed forth and back across my code?
Have a look at boost::function:
http://www.boost.org/doc/libs/1_36_0.../function.html
HTH,
Éric Malenfant