函数指针三种方法

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

  

猜你喜欢

转载自www.cnblogs.com/mayichen0823/p/10188810.html