读书人

函数指针使用不明白=(*(SFunc[Trans

发布时间: 2012-09-23 10:28:11 作者: rapoo

函数指针使用不明白,请教大家=(*(SFunc[TransFlow->sNo]._Func))(TransFlow);

C/C++ code
#include "stdio.h"struct _SFLOW{    int  sNo;    void *Pointer;                                struct _SFLOW *NextFlow;           };typedef struct                                            {    unsigned char(*_Func)(struct _SFLOW *TransFlow);}_FUNC;unsigned char _Verify(struct _SFLOW *sFlow){    return 1;}unsigned char _VerifyTwo(struct _SFLOW *sFlow){    return 2;}//// 这是一个常指针数组,就是里面返回的函数地址不能改变。_FUNC const SFunc[]={       _Verify,    _VerifyTwo,};void main(){    unsigned char result=0;    struct _SFLOW *TransFlow= NULL;    result =(*(SFunc[TransFlow->sNo]._Func))(TransFlow);//看不懂这个._Func是什么意思?}我理解_Func是个函数指针,函数指针也就是一个指针变量,这个指针变量是指向函数地址的指针。然后定义一个常指针数组,就是里面返回的函数地址不能改变。但调用的时候,不明白为什么是._Func。难道Func是他的成员?但他有不是结构体数组啊?


[解决办法]
C/C++ code
_FUNC const SFunc[]={       _Verify,    _VerifyTwo,};
[解决办法]
unsigned char(*_Func)(struct _SFLOW *TransFlow);
----------------------
这个是返回值为unsigned char,以struct _SFLOW 结构体指针为参数的函数的函数指针

读书人网 >C语言

热点推荐