首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

如何在链表里面家函数指针

2012-03-09 
怎么在链表里面家函数指针啊我定义了一个链表structTableNode{stringrule//规则段int(*action)()//行为

怎么在链表里面家函数指针啊
我定义了一个链表
struct   TableNode
{
    string       rule;//规则段
    int   (*action)();//行为段   指向行为函数
    TableNode   *next;
};
插入函数:
int   InsertAfter(Table   P,string   e,int(*a)())//向表中插入指定节点后面插入新节点
{
    if   (P==NULL)   return   0;
    TableNode   *Q=new   TableNode;
    Q-> rule=e;
    Q-> action     =a;
    Q-> next   =P-> next   ;
    P-> next=Q;  
    return   1;
}
我想在遍历链表的时候就执行函数
int   (*pfunction)()=0;
  pfunction=a11;
可是在我执行插入的时候
  InsertAfter(T1,zifu,pfunction);
他说d:\my   program\decisiontable\decisiontable.cpp(39):   error   C2664:   “InsertAfter”   :   不能将参数   3   从“int   (__cdecl   *)(void)”转换为“int   *”


[解决办法]
函数指针需要typedef一下,有类型就OK了
typedef int(*a)()

热点排行