指向函数的指针
来源:互联网 发布:零基础编程入门 编辑:程序博客网 时间:2024/06/10 20:43
#include <iostream>#include <string>#include <vector>using namespace std;typedef bool (*cmpFcn) (const string&, const string&);// typedef简化指针的定义,bool lengthCompare(const string &s1, const string &s2){return s1.size() == s2.size();}void ff(vector<double> vec){cout << "ff(vector<double> vec)" << endl;}void ff(unsigned int x){cout << "ff(unsigned int x)" << endl;}int demo (int *p, int a){return 12;}int (*ff(int x))(int *, int) //ff是一个函数,有一个形参x,返回结果是一个函数指针,int(*)(int *, int){cout << x << endl;return demo;}void useBigger(const string &s1, const string &s2, bool (*pf)(const string&, const string&)){cout << pf(s1,s2) << endl;}int main (){bool (*pf)(const string &, const string &); // pf是一个指针,指向函数的指针:函数类型,void (*pf7)(vector<double>) = &ff;cmpFcn pf4 = lengthCompare;useBigger("hi", "function", pf4); // 函数的名称就是一个指针,int a = 5;int *pa;cout << ff(2)(&a, a) << endl; // 一个输出是2,另一个输出是12,//pf 是一个局部变量,// bool (*pf2)(const string&, const string&); //bool (*pf3)(const string&, const string&); cmpFcn pf2;cmpFcn pf3 = 0;pf2 = lengthCompare;pf3 = lengthCompare;pf = &lengthCompare;cout << lengthCompare("hello", "pointer") << endl; // 输出是0,cout << (*pf)("hello", "point") << endl; // 输出是1,return 0;}
0 0
- 指向函数的指针
- 指向函数的指针
- 指向函数的指针
- 指向函数的指针
- 指向函数的指针
- 指向函数的指针
- 指向函数的指针
- 指向函数的指针
- 指向函数的指针
- 指向函数的指针
- 指向函数的指针
- 指向函数的指针
- 指向函数的指针
- 指向函数的指针
- 指向函数的指针
- 指向函数的指针
- 指向函数的指针
- 指向函数的指针
- 爬虫攻略
- [神经网络]2.1-How the backpropagation algorithm works-Warm up: a fast matrix-based approach ...(翻译)
- 从零开始使用C ++和OpenGL编写游戏引擎
- 字符串转成数字
- 与众不同的家装!超有创意的种植“壁画”
- 指向函数的指针
- Stanford 机器学习 Week4 作业 Multi-class Classification and Neural Networks
- 抽象类和接口的区别
- 基本套接字编程
- Android edittext输入图片
- mac下面用哪种远程控制,vnc还是teamViewer
- Google USB Driver
- 计算机网络性能
- COM中的OLECHAR ,BSTR和CComBSTR 的理解和应用