C++ boost::function














































C++ boost::function



 It is also possible to assign class member functions to  objects of type boost::function.
Code:
#include <boost/function.hpp> #include <functional> #include <iostream> struct world { void hello(std::ostream &os) { os << "Hello, world!\n"; } }; int main() { boost::function<void(world*, std::ostream&)> f = &world::hello; world w; f(&w, std::ref(std::cout)); }

Explanation:
When calling such a function, the first parameter passed indicates the particular object for which the function is called. Therefore, the first parameter after the open parenthesis inside the template definition must be a pointer to that particular class. The remaining parameters denote the signature of the corresponding member function.

Comments