关于函数指针的问题???指针解除引用和没有接触引用结果是一样的???why???程序可直接运行
我的问题写在注释了,大牛解释下撒,谢了
#include <iostream>
using namespace std;
double squared(double);
double cubed(double);
double sum_arry(double arry[],int len,double (*pfun) (double));
int main()
{
double arry[]={1.5,2.5,3.5};
int len=sizeof arry/sizeof arry[0];
cout<<"Squared:"<<sum_arry(arry,len,squared)<<endl;
cout<<"Cubed:"<<sum_arry(arry,len,cubed)<<endl;
return 0;
}
double squared(double x)
{
return x*x;
}
double cubed(double x)
{
return x*x*x;
}
double sum_arry(double arry[],int len, double (*pfun) (double))
{
double total=0;
for(int i=0;i<len;++i)
total+=(*pfun)(arry[i]); //我想强调这里,为什么(*pfun)和pfun的效果一样???
return total;
}