C/C++ 函数指针
来源:互联网 发布:土建计价软件 编辑:程序博客网 时间:2024/06/08 01:01
声明函数指针,必须指定指针指向的函数类型,例如:double pam(int);正确的指针类型为 double (*pf)(int)。与pam()声明类似,将pam替换为(*pf),这里可以pf=pam等式成立。
#include<iostream>double betsy(int);double pam(int);void estimate(int lines, double(*pf)(int));using namespace std;int main(){ int code; cout << "How many lines of code do you need?"<< endl; cin >> code; cout << "Here`s Betsy`s estimate:\n"; estimate(code, betsy); cout << "Here`s Pam`s estimate:\n"; estimate(code, pam); return 0;}double betsy(int lns){ return 0.5*lns;}double pam(int lns){ return 0.03*lns + 0.0004*lns*lns;}void estimate(int lines, double(*pf)(int)){ cout << lines << "lines will take"; cout << (*pf)(lines) << "hours(s)\n";}
这里传入pam和besty函数到estimate中的(*pf)参数
阅读全文
0 0
- C++,C函数指针
- C/C++:函数指针
- C++----函数&函数指针
- C指针函数 && 函数指针
- 【c/c++】指针函数和函数指针
- c++/c 函数指针用法
- C/C++_lesson_11_指针函数
- C/C++:C++函数指针
- C/C++__函数指针
- c++/c 函数指针详解
- C/C++·函数指针
- 【C和指针】函数指针
- 《c和指针》函数指针
- c语言函数指针
- C/C++函数指针
- C语言函数指针
- [C]函数指针数组
- C 函数指针
- Matlab 编程 Project Euler Problem 20 Factorial digit sum
- Django工具:Git简介与基本操作
- Android selector动态更改字体颜色
- Spring 声明式事务管理----基于AspectJ的XML方式
- uva 1395 Slim Span
- C/C++ 函数指针
- UVA 11419 SAM I AM (最小点覆盖)
- LeetCode习题笔记——Add Two Numbers
- Cookie管理
- <机器学习实战>--朴素贝叶斯(一)
- linux系统基本命令(九)
- 编码 —— PCM 编码
- 频率域图像增强及MATLAB实现
- hdu5033Building 单调栈