回调函数

作用:将自定义函数 做为指针传递给其他模块,当其他模块内达到某种状态时,执行此函数,运行自定义函数内容,通知自己一些所关注信息
例如如下使用:if other module percent == 100, let us know

/** if other module perent == 100, notify us
*/
// others module
int perent = 0;
OtherModuleFunc(void* inpCallBackFunc){
  // do some process...
  
if (percent == 100) {
    *inpCallBackFunc(percent);
  }
}
// our module
int percent = 0;
void GetPrcPercent(int inPercent){
  percent = inPercent;
}

int main() {
  OtherModuleFunc(GetPrcPercent);
  if (percent == 100) {
    //do some thing
  }
}

posted @ 2023-05-17 15:08  ldfm  阅读(12)  评论(0编辑  收藏  举报