Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: mem_fun_ref with 1 argument?

Reply
Thread Tools

Re: mem_fun_ref with 1 argument?

 
 
Raoul Gough
Guest
Posts: n/a
 
      08-26-2003
"Jimmy Johns" <(E-Mail Removed)> writes:

> Hi, I have a class defined like so:
>
> class foo {
> public:
> typedef std:air<double, double> ret_type;
> ret_type func1(double n) const // notice the const
> {
> // do soemthing
> // return ret_type
> }
> };
>
> now in a function:
>
> std::vector<double> v1;
> //put some stuff in v1;
> std::vector<foo::ret_type> res;
> std::transform(v1.begin(), v1.end(),
> std::back_inserter(res),
> std::mem_fun_ref(&foo::func1) // this line gives me problems.
> };


But func1 is a member function, so it needs an object to operate
on. IIRC, mem_fun_ref converts a member function into a function that
takes that object type as its first parameter. You still need to pass
it a foo object, though. Something like

std::bind1st (std::mem_fun_ref (&foo::func1), foo_object);

Should create a unary function that takes a double.

> okay, so I checked SGI's site on this, and there seems to be a mem_fun1_ref
> function that allows for a single argument, but that eventually resulted in
> the same error. I've also tried using bind2nd(mem_fun_ref(&foo::func1),
> *cit++), where cit is an iterator initially pointing to v1.begin(), but that
> gives an error as well. The error message is in algorithm header and the
> message is "term does not evaluate to a function". So now I'm pretty
> stumped. What is the proper way to do this??


Using an expression with a side-effect almost certainly won't do what
you want it to (it will only get evaluated once, before being passed
to bind2nd which returns an object containing a fixed value).

--
Raoul Gough
"Let there be one measure for wine throughout our kingdom, and one
measure for ale, and one measure for corn" - Magna Carta
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mem_fun vs mem_fun_ref Ioannis Vranos C++ 13 03-17-2005 09:21 PM
Re: mem_fun_ref with 1 argument? Ahti Legonkov C++ 0 08-26-2003 12:08 PM
Re: How to use bind2nd with mem_fun_ref? Michiel Salters C++ 0 07-16-2003 08:47 AM
Re: How to use bind2nd with mem_fun_ref? Jan Rendek C++ 0 07-15-2003 10:13 AM
mem_fun_ref Anders C++ 2 07-01-2003 01:02 PM



Advertisments