首页 > 其他 > 详细

函数指针三种方法

时间:2018-12-28 10:12:05      阅读:145      评论:0      收藏:0      [点我收藏+]
//函数指针定义
//1
typedef int(fun_point1)(int, int);
int get_sum(int a, int b)
{
	return a + b;
}


typedef int(*fun_point2)(int, int);

int main(void)
{
	//call function
	fun_point1* p = get_sum;
	int sum = p(3, 2);
	cout << "sum = " << sum << endl;


	fun_point2 p2 = get_sum;
	sum = p2(3, 4);
	cout << "sum = " << sum << endl;

    //经常使用
	int(*fun_point3)(int, int) = get_sum;  
	int n = fun_point3(6, 8);

	cout << "n =" << n << endl;

	system("pause");
	return EXIT_SUCCESS;
}

  

函数指针三种方法

原文:https://www.cnblogs.com/mayichen0823/p/10188810.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!