您的位置:首页 > 其它

函数指针基础语法C++

2018-01-14 19:29 288 查看
//#include "stdafx.h"
#include <iostream>

using namespace std;

int function(int a, int b)
{
cout << a << " + " << b << " = ";
return a + b;
}

int main()
{
int (*tp)(int, int);
tp = &function;
cout << tp(1, 0) << endl;

typedef int(type_func)(int, int);
type_func *tp1;                                             //定义指向函数的指针
tp1 = &function;
//tp1 = function;                                           //or    C版本
cout << tp1(1, 1) << endl;

typedef int(*type_p_func)(int, int);
type_p_func tp2;
tp2 = &function;
cout << tp2(1, 2) << endl;

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