首页 > 代码库 > C++ 数组指针

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 }    

 

C++ 数组指针