"Jimmy Johns" <> 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