1. 程式人生 > >函式指標三種方法

函式指標三種方法

//函式指標定義
//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;
}