use function pointer as parameter
2009-04-27 20:40
375 查看
//here is a simple demo:
#include <iostream>
using namespace std;
void fun(void (*p_fun)());//attention: here '(*p_fun)' ,the parentheres cannot be omitted
//this means 'p_fun' is a function pointer
void fun1();
void fun2();
int main() {
fun(fun1);
fun(fun2);
return 0;
}
void fun1(void) {
cout<<"this is fun1!"<<endl;
}
void fun2(void) {
cout<<"this is fun2!"<<endl;
}
void fun(void (*p_fun)()) {
(*p_fun)();
}
#include <iostream>
using namespace std;
void fun(void (*p_fun)());//attention: here '(*p_fun)' ,the parentheres cannot be omitted
//this means 'p_fun' is a function pointer
void fun1();
void fun2();
int main() {
fun(fun1);
fun(fun2);
return 0;
}
void fun1(void) {
cout<<"this is fun1!"<<endl;
}
void fun2(void) {
cout<<"this is fun2!"<<endl;
}
void fun(void (*p_fun)()) {
(*p_fun)();
}
相关文章推荐
- Arduino: struct pointer as function parameter
- How to Use a Function or a Procedure as a Parameter in another Function
- How to use Metadata as search parameter in Advance Search Web Part
- Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning
- 编译错误error C2587: '_U' : illegal use of local variable as default parameter的问题
- How to use the pointer of function in a class?
- java call so :only use one struct as input and output parameter
- Output parameter not allowed as argument list prevents use of RPC.
- C++: Function as template parameter, example
- [Swift] function pointer(address) as the parameter of function
- pointer use as array
- C++ AMP: uses tile_static(lds) as function param: 2 methods ( array or Pointer)
- experiment : use class member function pointer
- [C++0x] Boost Thread in Vector and use lamda as thread function
- How do I declare and use a pointer to a class member function?
- !!!argc and argv as parameter of main function
- linux sh : user array as function's input or output parameter
- <errors>'MessageBoxA' : function does not take 1 parameter
- Cannot use object of type yii\db\Connection as array
- [Matlab] Attempt to execute SCRIPT *** as a function