#include #include #include #include class X { public: std::string text() { return std::string("hello world!"); } }; class Y { public: int value() { return 5; } }; class Z { public: bool isEnabled() { return true; } }; // [...] // There could be hundreds of classes like X, Y and Z int main() { { boost::function f; f=&X::text; X x; std::cout << "x.text() is " << x.text() << std::endl; std::cout << "f(&x) is " << boost::any_cast(f(&x)) << std::endl; } { boost::function f; f=&Y::value; Y y; std::cout << "y.value() is " << y.value() << std::endl; std::cout << "f(&y) is " << boost::any_cast(f(&y)) << std::endl; } { boost::function f; f=&Z::isEnabled; Z z; std::cout << "z.isEnabled() is " << z.isEnabled() << std::endl; std::cout << "f(&z) is " << boost::any_cast(f(&z)) << std::endl; } return 0; }