[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Function address vs. pointer to member function

Ramon F Herrera

9/18/2009 4:18:00 PM


(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_examp...

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-me...

2 Answers

Ramon F Herrera

9/18/2009 6:44:00 PM

0

On Sep 18, 12:17 pm, Ramon F Herrera <ra...@conexus.net> wrote:
> (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_examp...
>
> 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-me...


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
}

pjb

9/21/2009 8:52:00 AM

0

Ramon F Herrera <ramon@conexus.net> writes:

> On Sep 18, 12:17 pm, Ramon F Herrera <ra...@conexus.net> wrote:
>> (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_examp...
>>
>> 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-me...
>
>
> 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.



--
__Pascal Bourguignon__