Hi,
I am having some problem using std::bind1st() and mem_fun. I want to
bind member function calls to some kind of functor so it can be called
later.
The following works fine for me:
class Foo
{
std::string name;
public:
Foo() : name("mike") {}
std::string getName()
{
return name;
}
void setName(std::st ring n)
{
name = n;
}
};
typedef std::binder1st< std::mem_fun1_t <void, Foo, std::string
SetterFunc;
main()
{
Foo foo;
SetterFunc f = std::bind1st(me m_fun(&Foo::set Name), &foo);
std::string test("testing") ;
f(test);
std::cout << "after call, name is " << foo.getName() <<
std::endl;
}
But when I want to bind the getName() method, I have lots of trouble:
typedef std::binder1st< std::mem_fun_t< std::string, Foo GetterFunc;
GetterFunc y = std::bind1st(me m_func(&Foo::ge tName), &foo);
I think I don't want to use bind1st because the getName() method takes
no parameters? Is there a std::bind() ?
Also, what if setName() takes "const std::string&" instead of just
"std::strin g" ? Do I need mem_fun_ref or some const variation of it?
Thanks for any tips.