类函数调用自身的回调函数

来源:互联网 发布:苹果怎样申请网站域名 编辑:程序博客网 时间:2024/05/16 07:27

在某些情况下,我们需要在类自己的成员函数中,调用自己的另外一个成员函数,而这个成员函数的参数个数都是相同的,只是名字不同,那么可以考虑用到回调函数的方法,其具体做法是

class CProcess{public:typedef void (CProcess::*FuncCallBack)( int nValue, int nOther );void Process(){ProcessFunc(&CProcess::Func);}protected:void ProcessFunc( FuncCallBack pFunc ){//一些其他事务处理//...if (pFunc)(this->*pFunc)(2,3);//一些其他事务处理//...}void Func( int nValue, int nOther ){//处理一些逻辑//...}};


 

原创粉丝点击