函数指针
小栗子
#include <iostream>
using namespace std;
double f(int c){
return 2*3.14*c;
}
void main(){
typedef double (*Fp)(int);
Fp fp;
fp = f;
double d = (*fp)(5);
cout<<d;
}#include <iostream>
using namespace std;
double f(int c){
return 2*3.14*c;
}
void main(){
double (*fp)(int);
fp = &f;// 等价于fp=f;
double d = fp(5);//等价于(*fp)(5)
cout<<d;
}教室好冷>.<要不是要来补查C++作业,我可以在我大仙林的有暖气的教室自习的
上面的有没有取地址符号都不重要,因为本来f就是代表地址信息存储的
C++函数指针实例
本文通过两个具体的C++代码示例介绍了如何定义和使用函数指针,包括函数指针类型的声明、赋值及调用过程。
1万+

被折叠的 条评论
为什么被折叠?



