纯C环境下只能通过函数指针实现,如下:
#include <stdio.h>
void fun()
{
printf("hello,world/n");
}
struct test
{
void (*Fun)();
};
int main()
{
struct test _t;
_t.Fun = fun;
(*_t.Fun)();
return 0;
}
下面的方式将会报错:
#include <stdio.h>
struct test
{
void fun()
{
printf("hello,world/n");
}
};
int main()
{
struct test _t;
_t.fun();
return 0;
}
源贴:http://topic.youkuaiyun.com/u/20080625/19/4f35088b-ad38-406b-844b-93496ddd4c27.html