函数指针
来源:互联网 发布:java if else同时执行 编辑:程序博客网 时间:2024/04/30 09:27
1.简要介绍
2.使用示例
函数指针的一般用法:
#include "stdafx.h"typedef int (*AddCommFunc)(const int &a, const int &b);int AddRight(const int &a, const int &b){return (a + b);}int AddError(const int &a, const int &b){return (a - b);}int _tmain(int argc, _TCHAR* argv[]){AddCommFunc pfn = NULL;pfn = AddRight;int result = pfn(1, 2);return 0;}
3.问题
如果函数指针指向的是类的成员函数,怎么处理
#include "stdafx.h"class CalcClass;typedef int (CalcClass::*AddCommFunc)(const int &a, const int &b);class CalcClass{public:int AddRight(const int &a, const int &b){return (a + b);}int AddError(const int &a, const int &b){return (a - b);}protected:private:};int _tmain(int argc, _TCHAR* argv[]){CalcClass *pC = new CalcClass;AddCommFunc pf= &CalcClass::AddRight;int result = (pC->*pf)(1, 2);return 0;}
在定义函数指针的时候要加上类限定符
在调用函数指针的时候还是要加上*
- 指针函数 函数指针
- 函数指针/指针函数
- 指针函数&函数指针
- 函数指针 指针函数
- 函数指针 指针函数
- 指针函数,函数指针
- 函数指针,指针函数,
- 指针函数,函数指针
- 函数指针 指针函数
- 函数指针、指针函数
- 指针函数&函数指针
- 函数指针 指针函数
- 函数指针 指针函数
- 函数指针&指针函数
- 指针函数 函数指针
- 指针函数 &函数指针
- 函数指针&指针函数
- void指针 函数指针
- Core Java (十一) Java 继承,类,超类和子类
- SQL Server的聚集索引和非聚集索引
- 使用Log4j进行日志操作(经典)
- make sure that /opt/google/chrome/chrome-sandbox is owned by root and mode 4755
- Qt使用预处理文件
- 函数指针
- 屏幕截图程序(WTL)
- B+树索引-【高扇出性】
- 组合测试法中的全对偶测试法
- 二分法常用模板
- arm-linux-系列工具,ld,ar,as,objcopy (转)
- ARM Cortex-A9 NEON性能初步测试
- Java枚举的七种常见用法
- 自开发的一个日志模板