c++ 函数指针使用实例
2017-01-10 17:57
871 查看
#include <iostream> double add(double x , double y) { return x + y; } double sub(double x , double y) { return x - y; } double acc(double x , double y) { return x * y; } double calculate(double x , double y , double (*fun)(double ,double)) { return (*fun)(x , y); } int main() { using namespace std; double (*fun[3])(double , double) = {add , sub , acc}; const char (*guugle[3]) = {"sum" , "diff" , "accumlate"}; double a , b; cout << "Enter pairs of numbers (q to quit):" << endl; int i; while(cin >> a >> b) { for(i = 0 ; i < 3 ; i++) { cout << guugle[i] << " = " << calculate(a , b , fun[i]) << endl; } } return 0; }
相关文章推荐
- libc++abi.dylib: terminate_handler unexpectedly threw an exception
- c语言数组小练习
- Ubuntu下用C语言实现客户端服务器交互
- 针对第三方SDK中不恰当的char *类型的几点看法
- 统计某类完全平方数
- More C++ Idioms
- C/C++ OpenCV之Scharr边缘检测
- C语言程序设计---10:利用文件保存数据
- C语言宏中"#"和"##"的用法
- C/C++位域知识小结
- C语言格式输出
- C/C++ OpenCV之Laplacian边缘检测
- c++ primer plus 第五版 第七章 编程练习 第 8 题 (字符数组转成字符串,trim使用,判断空行)
- C/C++ OpenCV之Sobel边缘检测
- Effective C++读书笔记之确定对象被使用前已被初始化
- 1233: 华科版C语言程序设计教程(第二版)习题6.7
- c++中基类虚函数表的深入解析
- c++类型转换
- 裴波那契数列与应用
- 韩信点兵