Boost logo

Boost Users :

Subject: Re: [Boost-users] Having trouble with a callback function (converted to a class) in Regex
From: Ramon F Herrera (ramon_at_[hidden])
Date: 2009-09-17 18:20:51


It seems that the problem I am having is related to this:

http://www.parashift.com/c++-faq-lite/pointers-to-members.html

Still, I would appreciate your kind assistance...

TIA,

-Ramon

Ramon F Herrera wrote:
>
> Hello,
>
> 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,
>
> -Ramon
>
>
> ===================================================
>
> int main(int argc, const char** argv)
> {
> std::string text;
> for(int i = 1; i < argc; ++i)
> {
> cout << "Processing file " << argv[i] << endl;
> std::ifstream fs(argv[i]);
> load_file(text, fs);
> // construct our iterators:
> boost::sregex_iterator m1(text.begin(), text.end(), expression);
> boost::sregex_iterator m2;
> std::for_each(m1, m2, &regex_callback);
> // copy results:
> cout << class_index.size() << " matches found" << endl;
> map_type::iterator c, d;
> c = class_index.begin();
> d = class_index.end();
> while(c != d)
> {
> cout << "class \"" << (*c).first << "\" found at index: " <<
> (*c).second << endl;
> ++c;
> }
> class_index.erase(class_index.begin(), class_index.end());
> }
> return 0;
> }


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