Re: mem_fun fun
flopbucket wrote:
What kind of trouble? Why couldn't you post non-working code
instead?
Thanks for your response, here is a non-working example:
#include<iostream>
#include<functional>
#include<string>
class Foo
{
std::string name_;
public:
Foo() : name_("mike")
{}
std::string getName()
{
return name_;
}
};
typedef std::binder1st<std::mem_fun_t<std::string, Foo> > GetterFunc;
int main(int, char **)
{
Foo foo();
GetterFunc f = std::bind1st(std::mem_fun(&Foo::getName),
&foo);
std::cout << f() << std::endl;
}
$ g++ tmp.cc
error: no type named `second_argument_type' in `class
std::mem_fun_t<std::string, Foo>'
Basically I would like to place the call foo->getName() into a functor
so I could call it later.
Right. Well, the problem is that 'bind1st' (and 'binder1st') need their
argument to be a function of two arguments. Since mem_fun(&Foo::getName)
returns a functor with only one argument, it cannot be use in 'bind1st'.
You probably should consider using 'bind' which overcomes the limitation
of "exactly two arguments" imposed by 'binder1st'. Or you could add
a dummy argument to 'getName', thus making it a function with a second
argument, sort of. A hassle, admittedly.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask