alaigle

prepare yourself to change the world!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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

posted on 2012-05-14 15:50  alaigle  阅读(511)  评论(0编辑  收藏  举报