函数参数为函数指针
来源:互联网 发布:js动画库 编辑:程序博客网 时间:2024/06/05 03:54
//函数参数为函数指针
#include<iostream>
using namespace std;
//C++ 11 方法声明类型别名具体可看我的其他博文
using pfunctype = int(int, int);
//做函数参数的函数指针//声明
int (*pfunc)(int, int);
//注意 :int *pfunc(int,int);这样定义是一个普通函数返回一个int型的指针
int sumandproduct(int a, int b, pfunctype *pfunc);
int product(int a, int b)
{
cout << "这两个数相减为" << (a - b) << endl;
return 0;
}
int sumandproduct(int a, int b, pfunctype *pfunc)
{
cout << "这两个数相加为" << (a + b) << endl;
(*pfunc)(a, b);//或pfunc(a,b)
return 0;
}
int main()
{
sumandproduct(4, 2, product);//或者&product;
system("pause");
return 0;
}
#include<iostream>
using namespace std;
//C++ 11 方法声明类型别名具体可看我的其他博文
using pfunctype = int(int, int);
//做函数参数的函数指针//声明
int (*pfunc)(int, int);
//注意 :int *pfunc(int,int);这样定义是一个普通函数返回一个int型的指针
int sumandproduct(int a, int b, pfunctype *pfunc);
int product(int a, int b)
{
cout << "这两个数相减为" << (a - b) << endl;
return 0;
}
int sumandproduct(int a, int b, pfunctype *pfunc)
{
cout << "这两个数相加为" << (a + b) << endl;
(*pfunc)(a, b);//或pfunc(a,b)
return 0;
}
int main()
{
sumandproduct(4, 2, product);//或者&product;
system("pause");
return 0;
}
1 0
- 函数参数为指针
- 参数为函数指针
- 函数参数为函数指针
- C++ 函数指针 函数名作为参数
- 返回函数的指针, 参数为函数指针。。。。。
- 指针、引用为函数参数传值
- 数组做函数参数退化为指针
- 数组名作为函数参数时会退化为指针
- 数组名作为函数参数时,退化为指针
- 指针函数 和 函数指针 指针为参数时使用堆内存
- 函数指针作为函数参数
- 函数指针做函数参数
- 函数指针作为函数参数
- 函数指针做函数参数
- 函数指针,指针函数,指针的指针做函数参数
- 指针与函数参数
- 指针作为函数参数
- 指针做函数参数
- Web Service 接口调用
- gem安装ruby包无法建立本地环境(failed to build gem native extension)
- 关于链表中去掉重复数值的问题
- linux下curl作用及重要函数
- SVN服务器在Ubuntu16.04下搭建多版本库详细教程
- 函数参数为函数指针
- TCP/IP、Http的区别
- 深入探讨 CSS 特性检测 @supports 与 Modernizr
- Learning a Part of C++(for ACM/ICPC) (1) 简介
- Linux下/proc目录简介
- r语言怎么做ROC曲线
- poj2481 Cows(树状数组)
- 在arcgis中提取、添加与删除Shape文件Z值
- python爬虫(3)五种方法通过黑板客第一关