一个简单的回调函数实例,用作回调的对象必须是static,否则不行
#ifndef BASE_H
#define BASIC_H
#include <iostream>
using namespace std;
//class Base;
//void(*pfun)(void);
void callerFun(void(*pfun)(void))
{ pfun();}
class Base
{
public:
Base(){};
~Base(){};
void foo()
{
callerFun( Base::calleeFun);
}
protected:
/*无法通过
void calleeFun(void )
{
cout<<"Callee"<<endl;
}
*/
static void calleeFun(void )
{
cout<<"Callee"<<endl;
}
};
void main(void)
{
Base b;
b.foo();
}
#endif