There is a way, with the use of boost::function::target() template method. But since boost::bind return unspecified type, witch do not yet provide a way to access arguments, you will need to write your own binder functor. Here is some example:
class MyClass
{
public:
void myMethod()
{
std::cout << "This is my Method" << std::endl;
}
};
struct MyFunctor
{
MyFunctor(MyClass* o, void (MyClass::*m)()): object(o),method(m){}
MyClass* object;
void (MyClass::*method)();
void operator() ()
{
return (object->*method)();
}
};
So now you can access:
MyClass myObject;
boost::function< void() > func= MyFunctor(&myObject, &MyClass::myMethod);
func();
assert( func.target<MyFunctor>()->object == &myObject );
Same as with the boost::any there is no way to have polymorphic access witch the target template method.
func's internals from? Is it from within the same scope in whichfuncis defined, or is it from within the scope of the functionfuncis passed on to?