Re: mem_fun_ref with 1 argument?

Discussion in 'C++' started by Ahti Legonkov, Aug 26, 2003.

  1. Jimmy Johns wrote:
    > class foo {
    > public:
    > typedef std::pair<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.
    > };
    > 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??


    std::mem_fun_ref(&foo::func1) creates an object that expects 2
    arguments. that should be called like this:

    foo ff;
    std::mem_fun_ref(&foo::func1)(ff, 1.0);

    but transform expects something that can be called with one argument.
    you should use std::bind1st to bind the left argument to some foo
    object:

    std::transform(v1.begin(), v1.end(),
    std::back_inserter(res),
    std::bind1st(std::mem_fun_ref(&foo::func1), ff) );

    --
    Ahti Legonkov
    Ahti Legonkov, Aug 26, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anders

    mem_fun_ref

    Anders, Jun 30, 2003, in forum: C++
    Replies:
    2
    Views:
    1,666
    tom_usenet
    Jul 1, 2003
  2. Jan Rendek
    Replies:
    0
    Views:
    490
    Jan Rendek
    Jul 15, 2003
  3. Michiel Salters

    Re: How to use bind2nd with mem_fun_ref?

    Michiel Salters, Jul 16, 2003, in forum: C++
    Replies:
    0
    Views:
    408
    Michiel Salters
    Jul 16, 2003
  4. Raoul Gough

    Re: mem_fun_ref with 1 argument?

    Raoul Gough, Aug 26, 2003, in forum: C++
    Replies:
    0
    Views:
    624
    Raoul Gough
    Aug 26, 2003
  5. Ioannis Vranos

    mem_fun vs mem_fun_ref

    Ioannis Vranos, Mar 17, 2005, in forum: C++
    Replies:
    13
    Views:
    6,999
    Pete Becker
    Mar 17, 2005
Loading...

Share This Page