函数指针作为结构体成员,实现函数注册

有时我们需要将函数作为结构体的成员,模拟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;
}



文章来自: 本站原创
Tags:
评论: 0 | 查看次数: 10885