Boost logo

Boost Users :

From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2008-09-02 16:52:58


On Tue, Sep 2, 2008 at 14:53, Kurt Kohler <kohler_at_[hidden]> wrote:
>
> struct X
> {
> double f(double x) { return x; }
>
> typedef boost::function<double (double)> ftype;
>
> double call(ftype func, double x);
>
> };
>
> int main(int argc, char *argv[])
> {
> X x;
> x.call(&X::f, 1.0); // Error occurs here
> }
>

&X::f requires 2 arguments (the this pointer and the function
argument), so it's storable in a boost::function<double(X*const,
double)>. Presumably you want this instead:

    x.call( bind(&X::f, x, _1), 1.0 );

HTH,
~ Scott


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