有時(shí)我們需要將函數(shù)作為結(jié)構(gòu)體的成員,模擬C++類的情形,可應(yīng)用于方法注冊(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;
}