C++回调函数原理举个简单的小程序例子

2025-02-25 06:43:42
推荐回答(3个)
回答1:

回调函数是使用函数指针实现的

#include
#include

typedef void (*Fun_t)(void);
void test(Fun_t fun, unsigned int t);
void handle()
{
printf("Hello!\n");
}

int main( )
{
test(handle, 5);
return 0;
}

void test(Fun_t fun, unsigned int t)
{
while (t--)
{
Sleep(1000);
}
fun();
}

回答2:

这写的还不错,你参考一下吧
https://baike.baidu.com/item/回调函数/7545973?fr=aladdin

回答3:

有这种叫法吗?是不是递归调用?