回调函数最简单用法
回调函数最简单用法
#include <iostream>
using namespace std;
int toZeroDown(int n, void *contex) {
cout << "toZeroDown:" << -*(int*)(contex) << endl;
return 0;
}
int toZeroUp(int n, void *contex) {
cout << "toZeroUp:" << *(int*)(contex) << endl;
return 0;
}
typedef int(*CallBackFunc)(int n, void *contex);
void registNumCallBack(CallBackFunc callback, void *contex)
{
int n = 3;
callback(n, contex);
}
int main()
{
for (int i = 0; i < 10; i++)
{
if (i % 2) {
registNumCallBack(toZeroDown, &i);
}
else
{
registNumCallBack(toZeroUp, &i);
}
}
}
本文来自博客园,作者:StimuMing,转载请注明原文链接:https://www.cnblogs.com/fole-del/p/15806660.html