文章目录
c/c++:回调函数
- 函数是一种function-to-pointer方式, 其会自动转换成指针的类型, &fun是该函数的地址, 为指针类型, fun是一个函数, 会转换成其指针类型, 而对于*fun, 由于fun已经变成了指针类型,
http://blog.csdn.net/callmeback/article/details/4242260/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include <stdio.h> #include<iostream> void printWelcome(int len) { printf("欢迎欢迎 -- %d/n", len); }
void printGoodbye(int len) { printf("送客送客 -- %d/n", len); }
void callback(int times, void(*print)(int)) { int i; for (i = 0; i < times; ++i) { print(i); } printf("/n我不知道你是迎客还是送客!/n/n"); } void main(void) { callback(10, printWelcome);
std::cout << std::endl<< "--------------------------------------------------------------------------------------------" << std::endl;
callback(10, printGoodbye); std::cout << std::endl << "--------------------------------------------------------------------------------------------" << std::endl; printWelcome(5); }
|
注册回调函数
https://blog.csdn.net/mrailence/article/details/52251201
回调函数demo
回调函数demo2
关于回调函数