Boost logo

Boost Users :

From: Alain Leblanc (aalebl_at_[hidden])
Date: 2007-07-04 09:11:39


Thanks for the reply. I'll give it a try when I have some time. For
now I found an easy way around the problem.

a

2007/6/30, John Maddock <john_at_[hidden]>:
> Alain Leblanc wrote:
> > Hi,
> >
> > I wrote some code where I want to iterate on the result of a regex
> > matching and call a member function for each match. It goes roughly
> > like this:
>
> > void XX::addDelayedVariables(string expr) {
> > funcPtr = &XX::regex_callback;
> > regex re("([[:alpha::]][[:alnum]]+)(\[[^\\]]+])");
> > sregex_iterator m1(expr.begin(), expr.end(), re);
> > sregex_iterator m2;
> > match_results<string::const_iterator> results; (*)
> > bool a = (this->*funcPtr)(results); (*)
> > for_each(m1, m2, (this->*funcPtr)); (#)
> > }
> > ===========================================================================
> >
> > When compiling (gcc 4.1 on FC 6) I get an error message at (#) that
> > says: invalid use of non-static member function
> >
> > I added the two lines with a (*) as a sanity check to see that I
> > declared the pointer-to-member-function correctly, and I have no
> > problem compiling those.
> >
> > So my question is: is this a problem with me not understanding how to
> > handle pointer-to-member-functions in C++, or is there something with
> > the boost libraries that I'm missing or is preventing me from
> > performing this operation? I would appreciate any help or opinion.
>
> The problem is that (this->*funcPtr) is an unmentionable and unusable type
> in C++. Yes, you can use it at the site of a function call, but not as a
> functor.
>
> I'm sure Boost.Bind or Boost.Lambda have solutions, or you can use:
>
> std::bind1st(std::mem_fun(&XX::regex_callback), this)
>
> to create a valid functor to pass to for_each.
>
> HTH, John.
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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