有時我們需要將函數作為結構體的成員,模擬C++類的情形,可應用于方法注冊。
#include <stdio.h>
struct a
{
??? void (*func)(char *);
};
void hello(char *name)
{
??? printf ("hello %s\n",name);
}
int main()
{
??? struct a a1;
??? a1.func = hello;
??? a1.func("illusion");
??? system("PAUSE");
??? return 0;
}