boost::function to member function - "changing the instance of the class".

After i define a boost::function using bind to a member function of some signature... Can i change the instance to have as "this" in such function for another of the same type? Maybe pass it as a parameter at call time? Why would i want that? Imagine i have some class A that dispatches calls for a big amount of methods. The requests for such calls come serialized, and the method is selected by its name (string). So there should be a std::map<std::string, boost::function<some_signature> > to be able to make the actual call after i know what the name is without doing a switch or a huge ammount of ifs. So A has that map, and has it populated with member functions of itself. But i may have many instances of A. (actually, one for each of many threads). So having that map in each is a waste of resources. So maybe i could declare the map as static, so that it is shared between all instances of A. But to do that, i would need to be able to tell the function in the map im about to invoke, what its "this" should be at this time. Did i explain myself clearly? Thanks a lot for your time :)

On Thu, Aug 7, 2008 at 2:51 PM, Alejandro Martinez <elpeque2@gmail.com> wrote:
After i define a boost::function using bind to a member function of some signature...
Can i change the instance to have as "this" in such function for another of the same type? Maybe pass it as a parameter at call time?
Thanks a lot for your time :)
Try boost::bind(&YourClass::YourMethod, _1, <rest of parameters>) That will create a boost::function whose first parameter will be used as 'this' in hte method call. HTH Stuart Dootson

thank you
participants (2)
-
Alejandro Martinez
-
Stuart Dootson