聲明定義
古老方法:
//定義函數(shù)原型
typedef int(OnWsErrorCallback)(wstring msg);
//函數(shù)指針
OnWsErrorCallback *pCallback;
c++11開始推薦的方法:
//定義函數(shù)原型的指針
using OnWsErrorCallbackPtr int(*)(wstring msg);
//函數(shù)指針
OnWsErrorCallbackPtr pCallback;
使用
用靜態(tài)函數(shù)或匿名函數(shù)
//匿名函數(shù)
auto pCallA = [](wstring msg)->int{
return 1;
};
//靜態(tài)函數(shù)
static int XXXX::onCall2(){
return 2;
}
pCallback = pCall;
pCallback = onCall2;