头文件:1.h
#include
int nul_func();
int test1(int a,int b);
int test2(int a,int b,int c);
int test3(int a,int b,int c,int d);
int GetFunc(char *p,int (**pfunc)());
struct test
{
char *pName;
int (*pFunc)();
}fun[] = {
{"test1",test1},
{"test2",test2},
{"test3",test3},
{"nul_func",nul_func}
};
函数实现:15.c
#include "1.h"
#include
int GetFunc(char *p,int (**pfunc)())
{
int i=;
while( memcmp(fun[i].pName,"nul_func",) != )
{
if( memcmp(p,fun[i].pName,strlen(fun[i].pName)) == )
{
*pfunc = fun[i].pFunc;
return ;
}
i++;
}
printf("%s\n","No Such Func.");
return ;
}
int test1(int a, int b)
{
printf("a = %d, b = %d\n",a,b);
return ;
}
int test2(int a, int b, int c)
{
printf("a = %d, b = %d , c = %d\n",a,b,c);
return ;
}
int test3(int a, int b,int c,int d)
{
printf("a = %d, b = %d, c = %d, d = %d\n",a,b,c,d);
return ;
}
int nul_func()
{
printf("%s\n","No Such Func");
return ;
}
主函数:14.c
#include
int main()
{
int i;
int (*pFunc)();
char caName[] = "";
memcpy(caName,"test1",);
i = GetFunc(caName,&pFunc);
printf("%s\n",caName);
i = (*pFunc)(,);
memcpy(caName,"test2",);
i = GetFunc(caName,&pFunc);
printf("%s\n",caName);
i = (*pFunc)(,,);
memcpy(caName,"test3",);
i = GetFunc(caName,&pFunc);
printf("%s\n",caName);
i = (*pFunc)(,,,);
return ;
}
编译:gcc 14.c 15.c -o test
结果:./test
typedef 函数指针 数组 std::function
1.整型指针 typedef int* PINT;或typedef int *PINT; 2.结构体 typedef struct { double data;}DATA, *PDATA; //D ...
C++ 指向成员函数指针问题
成员函数指针与常规指针不同,一个指向成员变量的指针并不指向一个内存位置.通常最清晰的做法是将指向数据成员的指针看作为一个偏移量. class ru_m { public: typedef int (r ...
C基础--函数指针的使用
之前在看代码的时候,看了函数指针的使用,大体分为如下几类: 做一个function list,通过指针索引调用,使得处理功能类似的函数看起来更加清晰: 函数指针作为另一个函数的参数,用作回调: lin ...
函数指针玩得不熟,就不要自称为C语言高手(函数指针是解耦对象关系的最佳利器,还有signal)
记得刚开始工作时,一位高手告诉我说,longjmp和setjmp玩得不熟,就不要自称为C语言高手.当时我半信半疑,为了让自己向高手方向迈进,还是花了一点时间去学习longjmp和setjmp的用法.后 ...
C返回函数指针的函数
如下函数 char (*retCharWithInt(char, char))(int); 申明了函数指针retCharWithInt,该指针指向一个形参是(char,char),返回值是char(* ...
Day8 函数指针做函数参数
课堂笔记 课程回顾 多态 virtual关键字 纯虚函数 virtual func() = 0; 提前布局vptr指针 面向接口编程 延迟绑定 多态的析构函数的虚函数. ...
linux select函数详解
linux select函数详解 在Linux中,我们可以使用select函数实现I/O端口的复用,传递给 select函数的参数会告诉内核: •我们所关心的文件描述符 •对每个描述符,我们所关心的状 ...
linux系统调用函数---12
Linux应用编程学习笔记 周学伟 一.系统调用文件编程 1.文件打开函数 /*************************** ...
成员函数指针与高效C++委托 (delegate)
下载实例源代码 - 18.5 Kb 下载开发包库文件 - 18.6 Kb 概要 很遗憾, C++ 标准中没能提供面向对象的函数指针. 面向对象的函数指针也被称为闭包(closures) 或委托(del ...
随机推荐
Scrapy爬取自己的博客内容
python中常用的写爬虫的库有urllib2.requests,对于大多数比较简单的场景或者以学习为目的,可以用这两个库实现.这里有一篇我之前写过的用urllib2+BeautifulSoup做的一 ...
LINQ系列:LINQ to SQL Transact-SQL函数
1. CASE WHEN ... THEN ... var expr = from p in context.Products select new { 商品ID = p.ProductID, 商品名 ...
Tomcat常见问题汇总
1.在服务器上一定要开启-server参数 #直接在一堆注释下添加即可 #即是在 # OS specific support.注释之前 JAVA_OPTS= -server 2.tomcat启动很慢 ...
【LeetCode】Sort Colors
Sort Colors Given an array with n objects colored red, white or blue, sort them so that objects of t ...
PDU与SDU理解
惯例:首先标注定义,而后是形象的解释. PDU(Protocol Data Unit)协议数据单元 SDU(service data unit)服务数据单元 什么是协议数据单元?就是按照协议的要求来传 ...
T-SQL 创建、修改、删除数据库,表语法
CREATE 语句 CREATE语句的开头都是一样的,然后是特定的细节. CREATE 一.CREATE DATABAS ...
一个php user class
这个类叫php user class.php user class is an easy to use php snippet for user manipulation (register, log ...
Linux 安装USB摄像头
sudo apt-get update sudo apt-get install fswebcam sudo apt-get install mplayer sudo apt-get install ...
bzoj2005 NOI2010 方案统计
2005: [Noi2010]能量采集 Time Limit: 10 Sec Memory Limit: 552 MBSubmit: 4387 Solved: 2619[Submit][Statu ...
POJ 3258 River Hopscotch (最大最小距离)【二分】
题目大意:现在有起点和终点两个石块,这两个石块之间有N个石块,现在对这N个石块移除M个石块,使得这些石块之间的最短距离最大,注意,起点和终点这两个石块不能被移除. 解题分析: ...