嘿,所以我想弄清楚如何将函数指针传递给存储在结构中的函数。以下是typedef
struct menu_item
{
char name[ITEM_NAME_LEN+1];
BOOLEAN (*func)(struct vm*);
};
我试图传递的函数具有以下原型(prototype)。
void print_list(struct vm_node *root);
文件的定义是:
void print_list(struct vm_node *root) {
while (root) {
printf("%s",root->data->id);
root = root->next;
}
printf("\n");
}
最佳答案
struct menu_item item;
item.func = &print_list;
就这么简单。然而BOOLEAN (*func)(struct vm*);
需要改为void (*func)(struct vm_node *);
以匹配目标函数。
关于c - 我如何将函数指针传递给函数。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26228195/