template<typename T>
class MemberFunctionSlot : public SlotFunctorBase{
public:
//!成员变量的回调函数定义
typedef bool(T::*MemberFunctionType)(const EventArgs&);
MemberFunctionSlot(MemberFunctionType func, T* obj) :
d_function(func),
d_object(obj)
{}
virtual bool operator()(const EventArgs& args)
{
return (d_object->*d_function)(args);
}
private:
MemberFunctionType d_function;
T* d_object;
};
typedef bool(T::*MemberFunctionType)(const EventArgs&),定义了一个模板函数,T 是
某个类,MemberFunctionType 是T 的某个成员函数类型,就和静态函数类似,它的参数和
返回值与自由函数一样。d_object 是我们说的this,MemberFunctionType 是成员函数的地址。
如何调用呢?(d_object->*d_function)(args),相当于this->func(args)。这样成员函数就可
以被调用了