|
Boost Users : |
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-09-02 16:55:17
AMDG
Kurt Kohler wrote:
> I have some code that uses pointers to member functions (not
> boost.function). It compiles and works fine. But when I tried to convert
> the code to use boost.function, I got a mess of errors.
> I know I'm doing something wrong, but I have no idea what it is. A clue
> would be greatly appreciated.
>
When you use Boost.Function with member functions,
you need to pass "this" as the first argument.
#include <boost/function.hpp>
struct X
{
double f(double x) { return x; }
double g(double x) { return -x; }
typedef boost::function<double(X*, double)> ftype;
double call(ftype func, double x)
{
return func(this, x);
}
};
int main(int argc, char *argv[])
{
X x;
x.call(&X::f, 1.0);
x.call(&X::g, 2.0);
}
In Christ,
Steven Watanabe
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