Original Post
I'm trying to convert a void ()(void) member function for a derived class to a functor which takes a base class pointer as its parameter. I figured this should be possible since the derived member function is really void ()(Derived *). I'm expecting it to be convertable to a functor of void ()(Base *), following the usual implicit upcast rules. However, the compiler is giving me an invalid conversion from Base* to Derived*. I'm assuming this downcast is the result of some sort of mem_fun template magic. Any ideas how I can make this work?
#include <iostream>
#include <tr1/functional>
struct A
{
typedef std::tr1::function<void (A *)> F;
explicit A(const F &f) : f(f) {}
void Do()
{
f(this);
}
private:
F f;
};
struct B : A
{
B() : A(std::mem_fun(&B::MyF)) {}
private:
void MyF()
{
std::cout << "check" << std::endl;
}
};
int main()
{
B().Do();
return 0;
}