函数指针运用示例

int F1(int a, int b)
{
	return a + b;
}

int F2(int a, int b)
{
	return a - b;
}

int F3(int a, int b)
{
	return a * b;
}

int F4(int a, int b)
{
	return a / b;
}

void x6t7()
{
	using F = int(*)(int, int);
	vector<F> ver;
	ver.push_back(F1);
	ver.push_back(F2);
	ver.push_back(F3);
	ver.push_back(F4);

	int a = 4, b = 2;
	for (auto Fun : ver)
		cout << Fun(a, b) << "\t";
	cout << endl;
}

  

posted @ 2017-05-23 18:52  lineaar  阅读(164)  评论(0编辑  收藏  举报