怎么在链表里面家函数指针啊
我定义了一个链表
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)()