Function address vs. pointer to member function

R

Ramon F Herrera

(please refer to the thread "Having trouble trying to get the address
of a member function" for details)

The following sample program comes with the C++ Regex distribution. It
compiles and runs fine. Its purpose is to count the number of classes
in the input text file.

http://patriot.net/~ramon/regex_iterator_example.cpp.txt

I am having a real hard time trying to convert the code to a class.
The problem occurs in this statement:

std::for_each(m1, m2, &regex_callback);

Thanks,

-Ramon

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

Ramon F Herrera

(please refer to the thread "Having trouble trying to get the address
of a member function" for details)

The following sample program comes with the C++ Regex distribution. It
compiles and runs fine. Its purpose is to count the number of classes
in the input text file.

http://patriot.net/~ramon/regex_iterator_example.cpp.txt

I am having a real hard time trying to convert the code to a class.
The problem occurs in this statement:

std::for_each(m1, m2, &regex_callback);

Thanks,

-Ramon

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


Found a solution ("the" solution?). It was provided by the author of
the Boost.Regex library.

Due respect, but I don't like that kind of hacks at all. Will keep
that code outside of a class, as if it was C.

-Ramon

--------------------

#if BOOST_WORKAROUND(_MSC_VER, < 1300) && !defined(_STLP_VERSION)
boost::regex_grep(std::bind1st(std::mem_fun1
(&class_index::grep_callback), this),
start,
end,
expression);
#else
boost::regex_grep(std::bind1st(std::mem_fun
(&class_index::grep_callback), this),
start,
end,
expression);
#endif
}
 
P

Pascal J. Bourguignon

Ramon F Herrera said:
Found a solution ("the" solution?). It was provided by the author of
the Boost.Regex library.

Due respect, but I don't like that kind of hacks at all. Will keep
that code outside of a class, as if it was C.


Then you still haven't understood what OO is all about.


On the contrary, you should use classes to encapsulate all these kinds
of hacks! That's exactly what they were designed for!


So you can thereafter use these classes with a homogeneous look and
feel, and without having to use or see these hacks anymore.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top