您的位置:首页 > 其它

函数指针与回调函数

2016-02-12 17:53 302 查看
#include<iostream>
using namespace std;

void show(int a)
{
cout << a <<"....";
}

int add(int a, int b)
{
return a + b;
}
int sub(int a, int b)
{
return a - b;
}
void  func_test(int(*p)(int, int), int a, int b)    //回调函数
{
cout<<p(a, b)<<endl;
}

int main()
{
show(3);
void(*p)(int);    //函数指针
p = show;    //show函数名是地址
p(4);

func_test(add,4,5);
func_test(sub, 4, 5);

cout<<"hello"<<endl;
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: