class FuncRoot()
{
public:
virturl void RunAFun()=0;
}
template <typename T>
class BindFunc:public FuncRoot
{
Publib:
typedef int (T::*MumberFuncType)();
TestB(TestA* o,MumberFuncType fn):
object_(o)
,func_(fn)
{
}
virtual void RunAFun() override
{
(object_->*func)();
}
private:
MumberFuncType func_;
T* object_;
};
class TestB
{
Publib:
TestB(){}
void RunAFun()
{
func->RunAFunc();
}
void RegistAFunc(FuncRoot* func)
{
func_=func;
}
private:
FuncRoot* func_;
};
class TestA
{
public:
TestA()
{}
void RegistFunToB(TestB* b)
{
b->RegistAFunc(this,&TestA::func);
}
private:
int func()
{
int i=100;
return i;
}
};
int main()
{
TestA a;
TestB b;
a.RegistFunToB(&b);
b.RunAFun();
return 0;
}