您的位置:首页 > 其它

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)();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  function fun