[Function] Can't attach to member without parameters

I'm sure I'm missing something pretty fundamental here. I'm trying to set a boost::function to a member function without any parameters. The following code fails to build (using VS 2005, haven't tested anything else). If I set it to a non-member function it works fine. #include <functional> #include <boost/function.hpp> class test { public: int GetInt() { return 1; } }; int _tmain(int argc, _TCHAR* argv[]) { test inst; boost::function<int ()> getter; // Getting several errors where it appears that <int ()> isn't being handled // as a signature when being handled by mem_fun. Not sure whether that is related. getter = std::bind1st( std::mem_fun(&test::GetInt), &inst); return 0; }

Jared, std::bind1st was not meant to "freeze" operations, but just for simple currying scenarios. As such, it expects a binary function as input. For a more generic binder, use boost::bind. In fact, just replace std::bind1st with boost::bind (and, yes, you can then skip that mem_fun altogether) and include <boost/bind.hpp>. I.e., your problem had nothing to do with boost::function. Regards, David .--------------------------------------------. | http://blog.davber.com = blah, blah , blah | --------------------------------------------
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Jared McIntyre Sent: Wednesday, August 30, 2006 6:31 PM To: boost@lists.boost.org Subject: [boost] [Function] Can't attach to member without parameters
I'm sure I'm missing something pretty fundamental here. I'm trying to set a boost::function to a member function without any parameters. The following code fails to build (using VS 2005, haven't tested anything else). If I set it to a non-member function it works fine.
#include <functional> #include <boost/function.hpp>
class test { public: int GetInt() { return 1; } };
int _tmain(int argc, _TCHAR* argv[]) { test inst; boost::function<int ()> getter;
// Getting several errors where it appears that <int ()> isn't being handled // as a signature when being handled by mem_fun. Not sure whether that is related. getter = std::bind1st( std::mem_fun(&test::GetInt), &inst);
return 0; } _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
David Bergman
-
Jared McIntyre