#include <stdio.h> #include <malloc.h> struct Hello{ void (*sayHello)(char* name); }; void sayHello(char* name){ printf("hello, %s\n",name); } int main(){ struct Hello* hello=(struct Hello *)malloc(sizeof(struct Hello)); hello->sayHello=sayHello;//這個結構體有多少個函數,就要在這個有多少個結構體內,函數指針指向函數的聲明。 hello->sayHello("a"); free(hello); return 0; }
