码迷,mamicode.com
首页 > 其他好文 > 详细

函数指针三种方法

时间:2018-12-28 10:56:50      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:函数   main   success   call   使用   oid   get   cal   pause   

//函数指针定义
//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;
}

  

函数指针三种方法

标签:函数   main   success   call   使用   oid   get   cal   pause   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!