概述
//P246
#include<iostream>
using namespace std;
typedef const double *(*p_fun)(const double*,int);
const double *f1(const double ar[],int n);
const double *f2(const double [],int);
const double *f3(const double *,int);
int main()
{
double av[3]={1112.3,1542.6,2227.9};
//const double *(*p1)(const double *,int)=f1;
p_fun p1=f1;
auto p2=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;
cout<<"----------------------------------------------"<<endl;
cout<<"B区开始输出"<<endl;
//const double *(*pa[3])(const double *,int)={f1,f2,f3};
p_fun pa[3]={f1,f2,f3};
// auto pb=pa;
cout<<"这里是替换处"<<endl;
const double *(**pb)(const double *,int)=pa;
cout<<"Using an array of pointers to functions"<<endl;
cout<<"Address Value"<<endl;
for(int i=0;i<3;i++)
cout<<pa[i](av,3)<<":"<<*pa[i](av,3)<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"C区开始输出"<<endl;
cout<<"Using a pointer to a pointer to a function:"<<endl;
cout<<"Address Value"<<endl;
for(int i=0;i<3;i++)
//P247
cout<<pb[i](av,3)<<": "<<*pb[i](av,3)<<endl;
cout<<"pb[i]输出完毕"<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"这里开始D区的输出"<<endl;
cout<<"Using pointers to an array of pointers"<<endl;
cout<<"Address value"<<endl;
auto pc = &pa;
cout<<"下方开始加很多*进行尝试"<<endl;
cout<<(**pc)[0](av,3)<<": "<<*((*pc)[0])(av,3)<<endl;
// const double *(*(*pd)[3])(const double *,int)=&pa;
p_fun (*pd)[3]=&pa;
const double *pdb=(*pd)[1](av,3);
cout<<"此处开始输出pdb"<<endl;
cout<<"pdb = "<<pdb<<endl;
cout<<"*pdb = "<<*pdb<<endl;
cout<<(*(*pd)[2])(av,3)<<": "<<*(*(*pd)[2])(av,3)<<endl;
return 0;
}
const double *f1(const double *ar,int n)
{
return ar;
}
const double *f2(const double ar[],int n)
{
return ar+1;
}
const double *f3(const double ar[],int n)
{
return ar+2;
}
最后
以上就是慈祥春天为你收集整理的《C++ Primer Plus 第六版》P246-247代码参考P248中的7.10.4中的typedef进行简化后的结果的全部内容,希望文章能够帮你解决《C++ Primer Plus 第六版》P246-247代码参考P248中的7.10.4中的typedef进行简化后的结果所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复