Boost logo

Boost Users :

Subject: Re: [Boost-users] Having trouble with a callback function (converted to a class) in Regex
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-09-17 23:38:43


AMDG

Ramon F Herrera wrote:
> This is my first non-trivial, multi-file C++ program with classes and
> I bumped into a problem. See example from the Regex library below.
>
> The problem occurred after I converted the simple code below to a
> class (called "Pairs"). The troublesome statement is this one, where
> we attempt to take the address of a function.
>
> std::for_each(m1, m2, &regex_callback);
>
> My first compilation attempt produces an error message from the
> compiler, which is nice enough to offer a solution:
>
> pairs.cpp:247: error: ISO C++ forbids taking the address of an
> unqualified or parenthesized non-static member func
> tion to form a pointer to member function. Say
> `&Pairs::assignment_callback'
>
> So, following the compiler's suggestion, I changed the line above to
> this:
>
> std::for_each(m1, m2, &Pairs::assignment_callback);
>
> Now, I am getting an inscrutable (for me, anyway) error message:
>
> stl_algo.h:158: error: must use .* or ->* to call pointer-to-member
> function in `__f (...)'
>
> Thanks for your kind assistance,

Try

#include <boost/bind.hpp>

std::for_each(m1, m2, boost::bind(&Pairs::assignment_callback, _1));

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