[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.c++

mem_fun_ref stl question

puzzlecracker

10/8/2008 6:15:00 PM

Why do we need mem_fun_ref when we use bind1st or bind2nd functors??
or even without binders as in example below:

for_each( v2.begin( ), v2.end( ),
mem_fun_ref ( &NumVals::display ) );
cout << endl;

1 Answer

Victor Bazarov

10/8/2008 7:59:00 PM

0

puzzlecracker wrote:
> Why do we need mem_fun_ref when we use bind1st or bind2nd functors??
> or even without binders as in example below:
>
> for_each( v2.begin( ), v2.end( ),
> mem_fun_ref ( &NumVals::display ) );

Does that compile, at all?

> cout << endl;
>

'for_each' expects a functor that can be called like so:

F(blah)

.. A member function requires the object. 'mem_fun_ref_t' adapts the
call to itself (it is a functor) to the non-static member function it's
constructed with. What book are you reading that doesn't explain
adapters? Get a copy of Nicolai Josuttis' "The C++ Standard Library".

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask