C++ 数组指针

 1 #include<iostream>
 2 using namespace std;
 3 double calculate(double x ,double y ,double (*pf[3])(double,double));
 4 double add(double x ,double y);
 5 double att(double x ,double y);
 6 double app(double x ,double y);
 7 int main()
 8 {
 9     double (*ps[3])(double,double)={add,att,app};
10     double a ,b;
11     cout<<"Enter a X : "<<endl;
12     cin>>a;
13     cout<<"Enter a Y : "<<endl;
14     cin>>b;
15     double tal = 0.0;
16     for(int i=0;i<3;i++)
17     {//calculate(a,b,(double(**)(double,double)));
18                 //需要注意这里
19         tal = calculate(a,b,(double(**)(double,double))(ps+i));
20         cout<<tal<<endl;
21     }
22     return 0;
23 }
24 
25 double calculate(double x ,double y ,double (*pf[3])(double,double))
26 {
27     double temp = 0.0;
28     temp = (*pf)(x,y);
29     return temp;
30 }
31 
32 double add(double x ,double y)
33 {
34     return x+y;
35 }
36 
37 double att(double x ,double y)
38 {
39     return x*y;
40 }
41 
42 double app(double x ,double y)
43 {
44     return x/y;
45 }    

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。