程序例子:分三个部分
#include <iostream>
using namespace std;
const double * f1(const double *ar, int n);
const double * f2(const double ar[], int n);
const double * f3(const double ar[], int n);
int main (void)
{
double av[3] = {1112.3, 1542.6, 2227.9};
//PART 1
//定义函数指针
const double *(*p1)(const double *, int) = f1;
auto p2 = f2; //自动分配数据类型 相当于const double *(*p2)(const double *, int) = f2;
cout << "Using pointers to functions: " << endl;
cout << "Address Value" << endl;
cout << (*p1)(av,3) << " : " << *(*p1)(av,3) << endl;
cout << p2(av,3) << " : " << *(*p2)(av,3) << endl;
//PART2
//定义数组,由指针构成,其3个元素是指针类型
const double *(*pa[3])(const double *, int) = {f1, f2, f3};
auto pb = pa;
cout << endl << "Using an array of pointers to functions: " << endl;